Python: several inputs possibility? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Python: several inputs possibility?

Or rather - where you can make an interactive game using Python, with a possibility to separate users(players) inputs by a game process? So it won't ask user to insert values once, at the beginning, but will ask several times according to user's trajectory through the code. The game itself – text battle. You'll have dictionaries as playable characters, multi-level cycles which mean turns in game, and affection of user choices (inputs) on each time they run through same cycles

4th Jan 2024, 11:55 AM
mm-uranium-ore-is-delicious
mm-uranium-ore-is-delicious - avatar
6 Answers
+ 7
Osmoor , > interactive inputs with users can be done only in regular ide environment, but NOT in code coach playgrounds. > the general approach for repeated inputs can be solved by running the code or part of the code (including input() function) in a loop.
4th Jan 2024, 12:01 PM
Lothar
Lothar - avatar
+ 3
If you intent to publish your code as code bits and let others to play, you can place a comment at the very beginning and tell people they have to copy the code to somewhere else can run interactively.
4th Jan 2024, 12:36 PM
Wong Hei Ming
Wong Hei Ming - avatar
+ 2
Yes. But you better leave a message to tell user to input a value, otherwise it looks like the program do nothing.
4th Jan 2024, 1:11 PM
Wong Hei Ming
Wong Hei Ming - avatar
+ 1
How Wong Hei Ming writed, talk to your user in input... Say what he's need to type. e.g. a = int(input('How old are you: ')) Gl in your path.
4th Jan 2024, 2:11 PM
Vitor Requena
Vitor Requena - avatar
+ 1
Osmoor , Yes, an IDE (I use Pydroid 3 on my Android phone) will let you take input in a loop while a condition is true.
4th Jan 2024, 3:19 PM
Rain
Rain - avatar
0
import random a=int(input()) n=0 b=random.randint(1,10) while a!=b: a=int(input()) n+=1 print(n, "attempts to get", b) #so, if I use IDLE Python or sort of – itll allow me to input values in "while-cycle" without breaking the code untill the condition will be true? """ #more pretty? import random n=0 while int(input())!=random.randint(1,2): n+=1 print(n) """
4th Jan 2024, 1:04 PM
mm-uranium-ore-is-delicious
mm-uranium-ore-is-delicious - avatar