Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialYoussef Moustahib
7,779 Points(could not convert string to float: 'e')
My code is exactly like craigs, but when I type a letter instead of a number, I get this message:
What is the final sum? 20
What is the total number of people? e
oh no, thats not a valid value
(could not convert string to float: 'e')
I did not raise that exception or input that message?
1 Answer
Viraj Deshaval
4,874 PointsHi Youssef, Strings cannot be converted to integer or floating point number because if you try float('e') Python will try to convert the 'e' but as its not a number it will raise an exception. But if you try float('3') it will be converted to floating point number because 3 is a number in a form of string.
Catch here is: Strings are only converted to floating point number if you try to convert numbers represented as string. Note: float('This is number 3') will not be converted because its a combination of letters and numbers strings and Python gets confused.
Hope I have cleared your doubt. Let me know if you face any challenges.