0

I am trying to create a loop where the user is given choices 1-8 and if they do not choose 1-8, it loops them back around re-enter number 1-8. I am attempting to use a while loop with two conditions. What am I missing?

fm_select = int(input("Enter a number 1-8"))
while fm_select <= 8 and fm_select >= 1:
matthew-e-brown
  • 2,837
  • 1
  • 10
  • 29
Gordito
  • 11
  • 3

2 Answers2

3

Your ranges are wrong. You want the while loop to fail when they are correct, since you're trying to break out of the loop. So, you want your loop to check against every number that isn't between one and eight. Instead, do

fm_select = 0
while (fm_select < 1 or fm_select > 8):
    fm_select = int(input("Enter a number between one and eight: "))

"As long as their input is less than one or higher than eight, keep asking"

matthew-e-brown
  • 2,837
  • 1
  • 10
  • 29
1

something like this should work

while(True):
    fm_select = int(input("Enter a number 1-8"))
    if 0 < fm_select < 8:
        break
    print("try again")
 print("you have entered %d" %(fm_select) )
ron
  • 186
  • 7