assignment 6.5 python for everybody 1

assignment 6.5 python for everybody

text = "X-DSPAM-Confidence:    0.8475";
a= text.find(':')
b= text.find('5')
c= text[a+1:b+1]

d= float(c.lstrip())

print(d)

Here is what the above code is Doing:
1. The first line is a string that we are going to search.
2. The second line is a variable that stores the position of the colon.
3. The third line is a variable that stores the position of the 5.
4. The fourth line is a variable that stores the string between the colon and the 5.
5. The fifth line is a variable that stores the floating point number that is the result of stripping the whitespace from the string in the fourth line and converting it to a float.
6. The sixth line prints the value of the fifth line.

Similar Posts