+ 2
Why conversation into float is necessary here.....
num1 = float(input("Enter a number: ")) num2 = float(input("Enter another number: ")) result = str(num1 + num2) print("The answer is " + result)
2 Answers
+ 12
input returns a string type. If you just simply add them with a + they will get added string-wise -- will be concatenated.
If you want a numerical addition, you have to convert to a numerical type - either float or integer.
+ 5
You are already converting the input upon the user entering it. Just remove the str() conversion for the result variable and it should work fine...
result = num1 + num2
Explanation: You want to add the two floats together. Since they are already floats, you don't need any further conversion. You are converting the floats back to strings, nullifying the float conversion you performed on the inputs.