+ 24

python input

x = input (x) y = input (y) print (x+y) what's the problem?

29th Jul 2018, 2:57 AM
Life1219
Life1219 - avatar
133 Antworten
+ 126
x = int(input()) y = int(input()) print (x+y)
29th Jul 2018, 3:20 AM
NezhnyjVampir
+ 37
x = input("x:" ) y = input("y:" ) print(x+y)
1st Apr 2021, 10:03 AM
SKOROBEY
SKOROBEY - avatar
+ 17
Life1219 you have to input in 2 separate lines, like, 1 2 or let me now what input u are giving.
29th Jul 2018, 3:21 AM
Nikhil Dhama
Nikhil Dhama - avatar
+ 15
Life1219 that's because of not giving proper number of inputs. One minute, I'll make a post to show that EDIT ~ https://www.sololearn.com/post/20154/?ref=app
29th Jul 2018, 3:53 AM
Nikhil
Nikhil - avatar
+ 14
Life1219 do you get any errors?
29th Jul 2018, 3:50 AM
Nikhil
Nikhil - avatar
+ 11
n = input("What is your name? ") s = input("What is your surname? ") y = input("Write an year when you born: ") age = 2021 - int(y) print("Your name is " + n + ". " + "Your surname is " + s + ". " + "You have " + str(age) + " years.") Code works
5th Apr 2021, 9:56 AM
Жека Воробей
Жека Воробей - avatar
+ 9
Life1219 when the code asks for input, write a number (or a string would work too) and then press enter. Then give your second number or a string on the second line.
29th Jul 2018, 3:41 AM
Yash✳️
Yash✳️ - avatar
+ 8
Nikhil EOFerror
29th Jul 2018, 3:52 AM
Life1219
Life1219 - avatar
+ 7
x = input() y = input() print(x+y)
29th Jul 2018, 3:16 AM
Nikhil Dhama
Nikhil Dhama - avatar
+ 7
yash Nikhil Nikhil Dhama thanks. now i know.
29th Jul 2018, 3:59 AM
Life1219
Life1219 - avatar
+ 5
Nikhil Dhama it isn't work, too.
29th Jul 2018, 3:20 AM
Life1219
Life1219 - avatar
+ 4
NezhnyjVampir yash Nikhil Dhama I used code playground. but it doesn't work.
29th Jul 2018, 3:44 AM
Life1219
Life1219 - avatar
+ 4
x=int(input()) y=int(input()) print(x+y) This is correct
22nd Mar 2021, 6:19 AM
Запас -
Запас - - avatar
+ 4
You are taking string inputs from the user. When you try to print x+y, It concatenates the two inputs. If you are dealing with intergers, use the below code x = int(input()) y = int(input()) print(x+y) For float(decimal) values, use the below code x = float(input()) x = float(input()) print(x+y) For multiple integers inputs: x = (int(i) for i in input().split()) print(sum(x)) The above lines read multiple numbers from user and store them as tuple. But the problem is user should give the numbers in single line. sum(x) will add all numbers that are stored in x.
30th Aug 2021, 6:44 AM
Pardha Saradhi
+ 4
x=input("x") y=input("y") print(x+y)
13th Oct 2021, 5:35 PM
sofia badri
sofia badri - avatar
+ 4
x = input() y= input() print(x* y )
21st Oct 2021, 6:39 PM
EngFatima
EngFatima - avatar
+ 4
x = int(input()) y = int(input()) print (x+y)
26th Oct 2021, 6:56 AM
Ahmed Mohammed
Ahmed Mohammed - avatar
+ 3
The problem is that its a syntax error. Where the input function only takes a string value, as a parameter, which is a default message for the user before entering input value. Here x is a variable as its not surrounded by quotes. And thus an error.
14th May 2021, 12:30 PM
Nishant R
Nishant R - avatar
+ 2
x=int(input()) y=int(input()) print(x+y)
18th Mar 2021, 5:09 AM
Арсений Липовой
Арсений Липовой - avatar
+ 2
When you use the input() function , the space inside the braces is where your input( the thing you're writing in playground) is supposed to be. There should not be any variable in the braces. In the case where you are trying to write a prompt for the input, you can put a string in the braces. For clarification: x is a variable 'x' is a string
9th Sep 2021, 5:42 PM
Jce 123
Jce 123 - avatar