def choose():
decision = input( 'Do you ' + colored('run', ('blue')) + ' or ' +
colored('attack?', ('blue')) )
return decision
while choose(): if choose() == "attack": etc. elif choose() == "run": etc.
The interpreter then asks for the input and after it is inputted it asks again, and again, then the program proceeds normally. Why is this and how can I fix it?
You call the input routine only once and save the response. Check that saved value repeatedly, rather than going back to your user each time.
choice = choose()
while choice:
if choice == "attack":
etc.
elif choice == "run":
etc.
...
choice = choose()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.