Skip to content

Instantly share code, notes, and snippets.

@MichelleDalalJian
Created October 7, 2017 12:50
Show Gist options
  • Save MichelleDalalJian/f56d51efd58e189ea3df9bbd31dc9423 to your computer and use it in GitHub Desktop.
Save MichelleDalalJian/f56d51efd58e189ea3df9bbd31dc9423 to your computer and use it in GitHub Desktop.
6.5 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";
x = text.find(" ")
y = text[x:]
fy=float(y)
print(fy)
@luqkrzy
Copy link

luqkrzy commented Sep 28, 2020

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

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

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

@upskillstechnologies
Copy link

My Optimized Solution.

text = "X-DSPAM-Confidence: 0.8475"

Step 1. find 0
Step 2. making a slice of string
Step 3. converting into float
Step 4. printing step

print(float(text[text.find('0'):]))

@CodeLarule
Copy link

All solutions were helpful. thanks a bunch...

@CodeLarule
Copy link

Very short and precise

y = float(text[text.find(' '):])
print(y)

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