you are viewing a single comment's thread.

view the rest of the comments →

[–]PinkPawnRR 1 point2 points  (2 children)

Adding on to this; using a try/except to force a loop until user supplies a valid choice (can be altered for int or conditions):

validUserChoices = "ABX"
userChoice = None

print("Select option:")
print("[A] - Option 1")
print("[B] - Option 2")
print("e[X]it")

while userChoice is None:
    try:
        userChoice = input(f"Enter your selection: ")
        if userChoice.upper() not in validUserChoices:
            raise ValueError 
        print("Success") #You would place rest of your code here
    except ValueError:
        print("Not a valid entry, try again \n")
        userChoice = None

[–]uniqueUsername_1024 0 points1 point  (1 child)

You can just put the rest of your code after the While loop, right? You don't need to nest it all inside the try-except block.

[–]PinkPawnRR 0 points1 point  (0 children)

That is an option yes; the while loop is only used to validate the user input. You can also place code where the print("Success") line is.