+ 1

Why does this not produce num1 plus num2 as a calculation?

num1 = input("Enter a number: ") num2 = input("Enter a number: ") print(int(num1 + num2))

3rd Jun 2020, 11:19 AM
3.14
3.14 - avatar
4 Answers
+ 4
num1 = int(input("Enter a number: ")) num2 = int(input("Enter a number: ")) print(num1 + num2) Try this.. Default input is string so parse/convert the input itself
3rd Jun 2020, 11:22 AM
$hardul B
$hardul B - avatar
+ 4
You are adding strings and then converting it to int
3rd Jun 2020, 11:24 AM
Abhay
Abhay - avatar
0
Try int(input('enter number')) Gotta switch the type
3rd Jun 2020, 11:23 AM
Slick
Slick - avatar
0
Always remmeber : by default input from the user is always a string... So: You need to convert it to an int by using int() function... That is ....num1 = int(input()) Suggetion...use float() ..function when dealing with decimal numbers...
5th Jun 2020, 10:40 PM
felix Kiprop
felix Kiprop - avatar