簡體   English   中英

輸入錯誤時,如何再次請求相同的輸入?

[英]How can I ask for the same input again when there was incorrect input?

players = input("How many players?")
if players == "1":
    p1 +=1
elif players == "2":
    p2 +=1
else:
    print("Invalid Input")
    players = input("How many players?")

輸入無效的輸入后,如何使其他重復?

使用無限循環並在輸入后break

while True:
    players = input("How many players?")
    if players == "1":
        p1 += 1
        break
    elif players == "2":
        p2 += 1
        break
    else:
        print("Sorry, please pick 1 or 2. Let's try again")

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM