while True: data = input("Please enter a loud message (must be all caps): ") if not data.isupper(): print("Sorry, your response was not loud enough.") continue else: #we're happy with the value given. #we're ready to exit the loop. break while True: data = input("Pick an answer from A to D:") if data.lower() not in ('a', 'b', 'c', 'd'): print("Not an appropriate choice.") else: break
Here is what the above code is Doing:
1. We’re asking the user to enter a loud message.
2. We’re checking to see if the message is all caps.
3. If it’s not, we’re asking the user to enter a loud message again.
4. If it is, we’re breaking out of the loop.