+ 6
Is it possible to make a block of code in python that asks for user input only once and uses it each time the user hits 'run'.
a code in python which works like this- 1. user hits 'run' for first time and the code asks for user's name - user clicks 'submit ' and the code runs and ends.- 2. user hit 'run' for 2nd time and insted of asking for his/er name, it uses the name given in the first time. this way the person will be asked for input only for once. not each time he hots run. is it possible to make such code on SL in Python i've seen one of such kind in web(on SL)
3 Answers
+ 2
by 'hits run' do you also just mean inputs run?
You surely can.
To get you started,
Take input and use an infinite loop that only breaks when they want to. When they type run again add/save whatever was wanted. Same way you got the input.
This will 'work' on SoloLearn, but not well. All input must be done at the same time.
+ 2
@rrestoring Faith sorry bt i cant understand what you mean
cn u plz explain again..?
+ 1
If you take input:
example = input()
And surround it in a loop
while True:
example = input()
You can use the users input however you like
Just need to declare the variable earlier.
saved = ""
while True:
example = input()
if example == "run":
saved += example
elif example == "exit":
break
Something like that. It may not be exactly what you wanted, but hopefully close.