簡體   English   中英

如何在 2 次嘗試后更改用戶看到的消息

[英]How to alter the message the user is seeing after 2 attempts

我意識到這個問題對於大多數用戶來說可能是微不足道的,但是經過數小時的谷歌搜索后,我正在努力尋找方法。

如何在 2 次嘗試后更改用戶看到的消息? 如果用戶鍵入“right”兩次,則消息應該是“想一想?你在失落的森林 Go 左邊還是右邊?”

n = input("You are in the Lost Forest Go left or right? ")
while n == "right" or n == "Right":
    n = input("You are in the Lost Forest Go left or right? ")
print("You got out of the Lost Forest! \o/")

存儲用戶進度將很有用

go_right = 0 # 0 means that the user havent go to right

n = input("You are in the Lost Forest Go left or right? ")

while n == "right" or n == "Right":
    if n.lower() == "right":
        go_right += 1

    if go_right > 1: # If the user have go to right for 2 times, then...
        n = input("Think harder! You are in the Lost Forest Go left or right? ")
        go_right = 0 # Resets the variable
    else:
        n = input("You are in the Lost Forest Go left or right? ")

print("You got out of the Lost Forest! \o/")

這個怎么樣:

msg = "You are in the Lost Forest Go left or right? "
msg2 = "Think harder! You are in the Lost Forest Go left or right? "
repeated = 0

n = input(msg).lower()
while n == "right":
    repeated += 1
    n = input(msg2 if repeated>=2 else msg).lower()
    if repeated >= 2: repeated = 0

print("You got out of the Lost Forest! \o/")

在線演示

暫無
暫無

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

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