In simple calculator code at point where two userinput no are being added and stored in result 'str' is added before (a+b).WHY?
2 Answers
New Answerin 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?
2/4/2017 7:10:41 PM
chandranu dhabal2 Answers
New Answercause 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 +
Learn Playing. Play Learning
SoloLearn Inc.
4 Embarcadero Center, Suite 1455Send us a message