+ 2

How can i ask input from the user in Python?

29th Mar 2018, 2:27 AM
Ulhas Bharadwaj
Ulhas Bharadwaj - avatar
19 odpowiedzi
+ 5
By just copying the link to the code and adding it to your message, the code will be attached to your post. d: For the actual code itself, to get x and y to have a value specified by the user can be done by doing the following: x = int(input()) y = int(input()) This asks the user to enter a value, then it stores the value in the variable. To enter multiple values when prompted, just add the second value on a separate line, and it should be stored into the second variable. Hope this helped! d:
29th Mar 2018, 2:51 AM
Faisal
Faisal - avatar
+ 4
Yes it works just fine as @Faisal describes -
29th Mar 2018, 3:01 AM
BroFar
BroFar - avatar
+ 4
the one thing i personally don't like is when the window opens to input it does tell you how many integers to input or if it's a series of strings or an array
29th Mar 2018, 3:19 AM
BroFar
BroFar - avatar
+ 4
when you input x click the ↩ dropdown key or next line button on your keypad. ( shift key )
29th Mar 2018, 3:30 AM
BroFar
BroFar - avatar
+ 4
you should be able to: 50↩ 100 "GO ▶" assigning y as 100 I also did: 100↩ 50 "GO ▶" assigning x as 100
29th Mar 2018, 3:36 AM
BroFar
BroFar - avatar
+ 3
Ulhas Bharadwaj Are you able to show me the code that you're referring to?
29th Mar 2018, 2:44 AM
Faisal
Faisal - avatar
+ 3
This should be the one you're referring to ---> https://code.sololearn.com/cmpSJe9XmbOd/?ref=app
29th Mar 2018, 2:47 AM
Faisal
Faisal - avatar
+ 3
Thank you so much, Faisal :)
29th Mar 2018, 3:21 AM
Ulhas Bharadwaj
Ulhas Bharadwaj - avatar
+ 3
You will learn many things here young grasshopper - LOL When you snatch this cricket from my hand you will become the master and be free to leave :) Okay, I got a little Kung Fu flashback... But you got the picture right? ! ?
29th Mar 2018, 3:49 AM
BroFar
BroFar - avatar
+ 2
To do so, you can simply just assign a variable to a value of the function input() which prompts the user to enter something and converts it to a string. To change what is entered to an int can be done by surrounding the input() function with the int() function, converting the value the user entered to an integer.
29th Mar 2018, 2:39 AM
Faisal
Faisal - avatar
+ 2
I don't get how to ask for input in the code. When I run someone else's program, it clearly asks me to give an input. I don't know what word to use there. It might sound silly. but I'm pretty new to this...
29th Mar 2018, 2:42 AM
Ulhas Bharadwaj
Ulhas Bharadwaj - avatar
+ 2
yes
29th Mar 2018, 2:47 AM
Ulhas Bharadwaj
Ulhas Bharadwaj - avatar
+ 2
thing is, i want to ask the user for the values of x and y
29th Mar 2018, 2:48 AM
Ulhas Bharadwaj
Ulhas Bharadwaj - avatar
+ 2
idk why, but i'm getting an error when I give the user to choose his input. when only x input can be varied according to the user, the there is no problem, but the problem arises when i do the same to y
29th Mar 2018, 3:26 AM
Ulhas Bharadwaj
Ulhas Bharadwaj - avatar
+ 2
I'll try it
29th Mar 2018, 3:30 AM
Ulhas Bharadwaj
Ulhas Bharadwaj - avatar
+ 2
Ok, i get it now. I never knew you could give 2 inputs at one go... Thank you so much, Robert :)
29th Mar 2018, 3:42 AM
Ulhas Bharadwaj
Ulhas Bharadwaj - avatar
+ 2
yea :)
29th Mar 2018, 4:11 AM
Ulhas Bharadwaj
Ulhas Bharadwaj - avatar
+ 1
I've made it public, but is there a way through which I can directly link it here?
29th Mar 2018, 2:46 AM
Ulhas Bharadwaj
Ulhas Bharadwaj - avatar
+ 1
I'm getting an EOF error for line 2
29th Mar 2018, 3:33 AM
Ulhas Bharadwaj
Ulhas Bharadwaj - avatar