+ 1
If I can add an integer and a float, why do we have to convert the float to avoid an error?
If I can say "print(1 + 2.0)" and get 3.0, then why do I get an error in the following code if I remove the second "float" conversion? print(float(input("Enter a number: ")) + (float(input("Enter another number: "))
4 Antworten
+ 9
Because input() returns a string, if you don't cast the string to a float type you will be adding a float value with a string.
Hth, cmiiw
+ 5
You're welcome mate : )
+ 2
Bingo! That answers my question perfectly. Thanks!
+ 1
That's my wife. Unfortunately she isn't a programmer and couldn't help with my question. Bummer!