+ 2
string in the "simple calculator" lesson
why do we need the "str" in this code: elif user_input == "add": num1 = float(input("Enter a number: ")) num2 = float(input("Enter another number: ")) result = str(num1 + num2) print("The answer is " + result) im confused........
3 ответов
+ 1
print("The answer is"+result )
in this line "The answer is" is a string
and output is integer
we cannot add String and integer
So we have convert integer output in String to display with String...
+ 8
so that it doesn't try to use math on a string and error out... notice the plus sign in the print statement!
0
thx ahri and dinesh! :)