How could I use input() without I have to enter the result ? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

How could I use input() without I have to enter the result ?

hello I'm searching a means to actualize an input every time in order to answer to the computer quickly. sorry for my bad English thanks

14th Jan 2017, 10:29 PM
Thibaut Simon
Thibaut Simon - avatar
18 Answers
+ 3
OK try this while True: try: x=int(input("enter x")) #what you want to do print("you entered"+str(x)) #im doing it except keyboardinterpreterror: break it will ask you input every time and will return print data and if you press any key on keyboard it will stop
15th Jan 2017, 2:29 AM
Sun
Sun - avatar
+ 2
Sun I'm sure that could work but unfortunately my python don't know keyboardinterpreterror.. and internet too! But this is the kind of function that will help me
15th Jan 2017, 8:06 AM
Thibaut Simon
Thibaut Simon - avatar
+ 1
create a function .. which will give in input.. and after that call that every t milliseconds by using callbacks
14th Jan 2017, 10:41 PM
Pankaj Vaghela
Pankaj Vaghela - avatar
+ 1
print([input("what number do you want to add? ") for i in range(int(input("how many numbers do you want to add?")))])
15th Jan 2017, 12:18 AM
Badmephisto
Badmephisto - avatar
+ 1
Okay I just understood what you wanted, print(input("enter your text with spaces between different words").split())
15th Jan 2017, 8:48 AM
Badmephisto
Badmephisto - avatar
+ 1
Badmephisto your print function just put my input in a list but I have to press enter yet
15th Jan 2017, 10:28 AM
Thibaut Simon
Thibaut Simon - avatar
+ 1
you don't want to press enter any time?? did you try putting spaces between your words though.
15th Jan 2017, 10:29 AM
Badmephisto
Badmephisto - avatar
0
I'm sorry but I don't understand how I can create a function with an input because the function will stop immediately no? thanks
14th Jan 2017, 10:48 PM
Thibaut Simon
Thibaut Simon - avatar
0
it's called self-nesting def give_input: print "Doing stuff..." # do your stuff like giving inputs give_input #again same function will be called give_input
14th Jan 2017, 10:55 PM
Pankaj Vaghela
Pankaj Vaghela - avatar
0
no module to import? I have no idea that exist. I just know recursive function! I will try it
14th Jan 2017, 10:57 PM
Thibaut Simon
Thibaut Simon - avatar
0
that's in basics you don't any other module.. you will need other modules if you want to have some time gap between each inputs like this import sched, time s = sched.scheduler(time.time, time.sleep) def putInput: print "Doing stuff..." # do your stuff s.enter(60, 1, putInput) s.enter(60, 1, putInput) s.run()
14th Jan 2017, 11:02 PM
Pankaj Vaghela
Pankaj Vaghela - avatar
0
ok I have tried your first function like this def give_input(): print ("enter a number") u = input() give_input() and as I thinked the program stopped to wait my answer
14th Jan 2017, 11:11 PM
Thibaut Simon
Thibaut Simon - avatar
0
Okay what kind of inputs you'll put in?
14th Jan 2017, 11:14 PM
Pankaj Vaghela
Pankaj Vaghela - avatar
0
define an array of answers/inputs let's name it "answers" define variable for answer number let's say x=0 def give_input(): #print ("enter a number") u = answers[x] #give in input x++ #increment the value of x to get to next answer give_input() give_input()
14th Jan 2017, 11:17 PM
Pankaj Vaghela
Pankaj Vaghela - avatar
0
I'd like to input number to move a charachter in an array but I'd also like that I mustn't push enter
14th Jan 2017, 11:19 PM
Thibaut Simon
Thibaut Simon - avatar
0
I understand your function but how can the computer ask an answer because in your function there is any input()
14th Jan 2017, 11:31 PM
Thibaut Simon
Thibaut Simon - avatar
0
thanks you badmephisto but your print function wait an enter
15th Jan 2017, 8:04 AM
Thibaut Simon
Thibaut Simon - avatar
0
yes it is badmephisto and I don't understand what space between input could change that
15th Jan 2017, 10:33 AM
Thibaut Simon
Thibaut Simon - avatar