📜  如何为用户提供多个选项并一次又一次地提出相同的问题,直到用户说出其中一个选项 - Python 代码示例

📅  最后修改于: 2022-03-11 14:46:25.002000             🧑  作者: Mango

代码示例1
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