0

Learning some valuable lessons while programming my first python script. Can someone explain how this works?

I am trying to use essentially the following for a robust user input check.

check=-1        
while check not in range(len(menu)):
    check=input('select a menu option')

I've also tried substituting a variable holder for range(len(menu)) to no avail. What happens is the script just continually asks for input regardless.

Ultimately I will be adding to the options (for example, menu has 8 strings, but I have 10 options, so len(menu)+2), no need to include anything about this I can figure it out, I'm just baffled as to the above code.

Intuitively I imagine the above becoming

  • While check is not in range(len(menu))

  • While check is not in range(8)

  • While check is not in (0,1,2,3,4,5,6,7) (forgive me for [] vs ())

  • While check is not equal to 0 and check is not equal to 1, etc.

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
bwag174
  • 1
  • 1

0 Answers0