Pylon loop

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ozchadl
    New Member
    • Apr 2010
    • 26

    Pylon loop

    I am writing a program in Python 2.6 and need help with doing a loop.

    the user input can only enter "a1", "a2", a3", "a4", or "a5"

    any other input it should loop back

    if the input was valid it should continue.
    if the input was not valid it should get another input until it is valid


    thanks for your help
  • bvdet
    Recognized Expert Specialist
    • Oct 2006
    • 2851

    #2
    A while loop is used in the following example:
    Code:
    valid_input = ['a1', 'a2', 'a3', 'a4', 'a5']
    
    while True:
        print "Valid input is %s" % (", ".join(valid_input))
        s = raw_input("Enter valid input")
        if s in valid_input:
            break

    Comment

    Working...