+ 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
6 ответов
+ 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.
+ 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.
+ 2
Yes.
But you better leave a message to tell user to input a value, otherwise it looks like the program do nothing.
+ 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.
+ 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.
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)
"""