+ 1
Why using string?
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) Why in this program are we converting the sum to string value?
2 odpowiedzi
+ 3
python can't add a int/float to a string so it needs to be converted to string.
if you just do 'print(result)' you don't need to convert it to string.
By the way in other languages like Java/Javascript/... you add them and the conversion happens automatically, but not in python!
+ 1
Thanks