+ 1

Doubt on input

I am confused It takes the input as a string, but what if my calculations use numbers so how do I take the input in numbers? PLZZZ HELP

28th Nov 2016, 2:54 PM
Calden Rodrigues
Calden Rodrigues - avatar
4 odpowiedzi
+ 2
For example: number = int(raw_input()) or you can define your inputs in the code as an int(): number1 = input() number2 = input() result = int(number1) + int(number2) print result I hope you take the answer
28th Nov 2016, 3:03 PM
Miraç Akif Merttürk
Miraç Akif Merttürk - avatar
+ 1
number=int(input("please enter the first number")) number2=int(input("please enter the second number")) sum = number+ number2 print("the sum of your numbers is : %s." % (sum)) you get the input as string, convert them in integer, and print out the result as string. i hope it helps.
30th Nov 2016, 10:05 PM
Benedek Máté Tóth
Benedek Máté Tóth - avatar
0
thx
28th Nov 2016, 4:42 PM
Calden Rodrigues
Calden Rodrigues - avatar
0
Well ! that solution only works if you are on Python 2 (which you shouldn't use) because of raw_input() and the print statement. The solution in Python 3 (which you SHOULD use) is int(input()), raises ValueError if it is not an int Hope it helped
28th Nov 2016, 9:51 PM
Amaras A
Amaras A - avatar