Skip to content

Instantly share code, notes, and snippets.

@Mohamed2del
Last active May 23, 2024 18:22
Show Gist options
  • Save Mohamed2del/66f0b9a733e021f7537787be40febe43 to your computer and use it in GitHub Desktop.
Save Mohamed2del/66f0b9a733e021f7537787be40febe43 to your computer and use it in GitHub Desktop.
Write code using find() and string slicing (see section 6.10) to extract the number at the end of the line below. Convert the extracted value to a floating point number and print it out.
text = "X-DSPAM-Confidence: 0.8475";
startPos = text.find(':')
piece = text[startPos+1:]
end = float(piece)
print(end)
@YousifTheKind
Copy link

text = "X-DSPAM-Confidence: 0.8475";
x = text.find('0')
y = text.find('7')
z = text[x:]
z = float(z)
print (z)

@fannifelletar
Copy link

text = "X-DSPAM-Confidence: 0.8475";
found = text.find('0')
sliced = text[found:found+7]
print(float(sliced))

@imohammedmq
Copy link

check this one easy and simple

text = "X-DSPAM-Confidence: 0.8475";
t = text.find('0.8475')
number = text[t:]
print(float(number))

@NoddyMedia
Copy link

text = "X-DSPAM-Confidence: 0.8475";

we need to assign a variable to the word we want to find

stvalue = text.find('0.8475')

so from that string value we cut out the value from text string

value = text[stvalue:]
#Then we print out our Answer
print(float(value))

@JoseLuis-Luna
Copy link

text = "X-DSPAM-Confidence: 0.8475";
number= text.find('0')
ft=float(text[number:])
print(ft)

@lia93
Copy link

lia93 commented Dec 5, 2020

text = "X-DSPAM-Confidence: 0.8475"
x= text.find(":")
print(x)
y= text[x+1:]
print(y)
value=float(y)
print(value)

@hjuivc
Copy link

hjuivc commented Jan 7, 2021

Hei.
Here is my suggestion which works. This is only for help. Try yourself before copy code.

text = "X-DSPAM-Confidence:    0.8475";

find = text.find ('0.8475')

a = float(find)

print(text[find:])

@thuytrangnugget
Copy link

text = "X-DSPAM-Confidence: 0.8475";
print(float(text[text.find("0"):]))

@EvgenJY2K2
Copy link

#Example of a working code:

text = "X-DSPAM-Confidence:    0.8475";
f = text.find(' ')
n = text[f:]
print(float(n.lstrip()))

@RachaaelK
Copy link

text = "X-DSPAM-Confidence: 0.8475";
a=text.find('0')
print(float(text[a:]))

@justacuriousperson
Copy link

text = "X-DSPAM-Confidence: 0.8475"
start=text.find("0")
number= text[start:]
final=float(number)
print(final)

@ShiwangiW
Copy link

text = "X-DSPAM-Confidence: 0.8475"
f = text.find("0")
x = text[f:]
value = float(x)
print(value)

@Jobanputra02
Copy link

text = "X-DSPAM-Confidence: 0.8475"
print(float(text[text.find(':')+1:]))

@lizzie303
Copy link

text = ("X-DSPAM-Confidence : 0.8475")
atpos = text.find (" : ")
startpos = text.find (" 5 ",atpos)
host = text[atpos-4 :]
value = float(host)
print (value)

@Rinskiii
Copy link

Rinskiii commented Nov 5, 2021

text = "X-DSPAM-Confidence: 0.8475"
finding = text.find("0")
#print(finding) - you will see what is the ordinal number of the number zero
number = text [23:]
print(float(number))

@nzomoe
Copy link

nzomoe commented Apr 23, 2022

text = "X-DSPAM-Confidence: 0.8475"
space = text.find(':')
piece = text[space+1:]
print(float(piece))

this works

@sonlain
Copy link

sonlain commented Jun 15, 2022

text = "X-DSPAM-Confidence: 0.8475"
pos=text.find('0.8475')
new=text[pos:]
j=float(new)
print(j)

@Hewan-Leul
Copy link

text = "X-DSPAM-Confidence: 0.8475"
hewi = text.find(':')
hewi1 = text[hewi+1:]
hewi2 = float(hewi1)
print(hewi2)

@lazurs1
Copy link

lazurs1 commented Aug 21, 2022

3 lines:
text = "X-DSPAM-Confidence: 0.8475"
textNum=text.find('0')
print(float(text[textNum:len(text)]))

@lazurs1
Copy link

lazurs1 commented Aug 21, 2022

2 Lines: Better :)

text = "X-DSPAM-Confidence: 0.8475";
print(float(text[text.find(':')+1:]))

@lazurs1
Copy link

lazurs1 commented Aug 21, 2022

1 Line
print(float("X-DSPAM-Confidence: 0.8475"["X-DSPAM-Confidence: 0.8475".find(':')+1:]))

@lazurs1
Copy link

lazurs1 commented Aug 21, 2022

Smaller by 2 chars.
print(float("X-DSPAM-Confidence: 0.8475"["X-DSPAM-Confidence: 0.8475".find('0'):]))

@Abstracts26
Copy link

text = "X-DSPAM-Confidence: 0.8475"

x= text.find(' ')
z= text[x+1:]
z= float (z)
print (z)

@FarzadFahimifar
Copy link

text = "X-DSPAM-Confidence: 0.8475"
a=text.find(":")
b=float(text[a+1:].lstrip())
print(b)

@ArsalanAliMujtaba
Copy link

text = "X-DSPAM-Confidence: 0.8475"
text = float(text[text.find(':')+1:].lstrip())
print(text)

@Lichkolia
Copy link

text = "X-DSPAM-Confidence: 0.8475"
x = text.find("0")
z = text.find("5")

print(float(text[x:z + 1]))

@tahira2k16
Copy link

text = "X-DSPAM-Confidence: 0.8475"
start= text.find(':')
end=start[start+1:]
string=float(end)
print(string)

@Faythly
Copy link

Faythly commented Jul 1, 2023

Text = “X-DSPAM-Confidence: 0.8475”
Pos = Text.find(‘:’)
Piece = text {Pos+2:}
end= float(piece)
Print(end)

@afr0uz
Copy link

afr0uz commented May 23, 2024

text = "X-DSPAM-Confidence: 0.8475"
a = text.find(':')
f = float(text[a+1:])
print(f)

@afr0uz
Copy link

afr0uz commented May 23, 2024

text = "X-DSPAM-Confidence: 0.8475"
a = text.find('0')
f = float(text[a:])
print(f)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment