Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Unexpected input within a while loop
#1
In this preliminary while loop, the user is asked to input an advantage. If they input 1,2, or 3 they while loop should say "Your stats been updated" and it does. But it also does for anything else, which I don't want it to do. Any help is appreciated.

valid = {'1', '2', '3'}
advantage = " "
while advantage not in valid:
    advantage = input("Do you pick extra health [1], extra luck [2], or extra power [3]")

    break

print ("Your stats have been updated")
Thanks in advance
Quote
#2
remove the break
Quote
#3
Larz60+ solution woks, but just for completeness, here is an example of the loop using the break. You mix the two approaches in your code
valid = {'1', '2', '3'}
while True:
    advantage = input("Do you pick extra health [1], extra luck [2], or extra power [3]")
    if advantage in valid:
        break
print ("Your stats have been updated")
Quote

Top Page

Forum Jump:


Users browsing this thread: 1 Guest(s)