SY_13 SY_13 - 10 months ago 38
Python Question

Explicit float conversion in python gives ParseError

I'm learning python in Coursera, I tried the assignment for the course but am not getting the desired result. This program is supposed to extract '0.8475' and convert it to float before printing it.

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

Everytime I run this code, I get a
ParseError: bad input on line 5

What am I doing wrong?


As @ZdaR mentions, the call to the float function must pass the parameter inside the parentheses as p = float(s). I tested this in Python IDLE and the program worked correctly.

Also note that you should not end lines with ; in Python. The whitespace itself will handle that for you when you start a new line.