0

In simple calculator code at point where two userinput no are being added and stored in result 'str' is added before (a+b).WHY?

in the control structure lesson,in the simple calculator program, where the two user inputs are being added the code is ( 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 is there str in result = str(num1 + num2) what is the reason?

4th Feb 2017, 7:10 PM
chandranu dhabal
chandranu dhabal - avatar
2 Antworten
+ 7
cause u r converting floats to string so u can add the string "the answer is" + result, u can do that without the str too like this result = num1+num2 print("The answer is", result) with a , instead of +
4th Feb 2017, 7:56 PM
Kawaii
Kawaii - avatar
0
thank you so much
5th Feb 2017, 1:51 AM
chandranu dhabal
chandranu dhabal - avatar