Reputation: 11
So I'm making a very simple calculator as my first real project in python on to which I will add more features but now the problem is that it adds numbers literally so if i type 2
as the first number and 3
as the second it will give 23
:
This is my code
a = input ('Enter the first number')
b = input ('Enter the second number')
c = (a+b)
print (c)
Upvotes: 1
Views: 128
Reputation: 11070
In Python 2.7, input takes only numberical values. But in Python 3.x, input() returns a string. So you are literaaly concatenating two strings in your code. So, cast them to int
a = int(input ('Enter the first number'))
b = int(input ('Enter the second number'))
This converts the numbers to integers and then adds them
Upvotes: 1
Reputation: 250941
input
returns a string in py3.x, use int()
to convert that string to an integer:
a = int(input ('Enter the first number'))
b = int(input ('Enter the second number'))
Upvotes: 4