0

how to add two numbers .. accepting it from the user .. because 2+2 shows 22

5th Oct 2016, 3:10 PM
swapnil bhagat
5 Respostas
+ 6
a = input("number1") b = input("number2") add = int(a) +int(b) print(add)
5th Oct 2016, 7:05 PM
Koray
+ 4
the input of the user is always a string. Because of that you have to convert the input in integers, first before adding them.
5th Oct 2016, 3:22 PM
Amarie
+ 2
This happens because of input() function take input as a string. In your case when you in put 2 it take is as "2" so "2"+"2"="22" So you have to convert it in to integer. for this CRIS also show an example and another way is take it directly in to integer. i.e. X = int(input("Input Number 1: "))
6th Oct 2016, 1:56 AM
Nikhil
Nikhil - avatar
+ 1
any user input is considered to be a string. you have to convert it before adding it together
5th Oct 2016, 3:22 PM
Luke Armstrong
- 2
a=raw_input("num1 :") b=raw_input("num2 :") print a,b
9th Oct 2016, 11:35 AM
Ramadhan fitriyan