0
Using different consoles shows different results ..
Hello, I'm trying with the following code: elif user_input == "add" num1 = float(input ("Enter the first value: ")) num2 = float(input ("Enter the second value: ")) result = str(num1 + num2) print("The result is: " + result) If I run on Spyder Phyton 3.6 on my laptop I get concatenated numbers. With inputs 1 and 2, I got 12. If I run on online console or in this app I got 3. This is frustrating.. What is the reason for that and what is the general rule to follow? Thanks.
3 Réponses
+ 3
Calculate result first, use str() inside print() as follows:
result = num1 + num2
print("The result is: " + str(result))
Or, use format() as follows:
result = num1 + num2
print("The result is: {}".format(result))
This also will work:
print("The result is: {}".format(num1 + num2))
Hth, cmiiw
+ 1
Thanks! Both ways work!
+ 1
You're welcome, glad if it helps : )