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)
@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