简体   繁体   English

如何在 2 次尝试后更改用户看到的消息

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

I realize this question might be trivial for most users, but i am struggling to find the approach after hours of googling.我意识到这个问题对于大多数用户来说可能是微不足道的,但是经过数小时的谷歌搜索后,我正在努力寻找方法。

How to alter the message the user is seeing after 2 attempts?如何在 2 次尝试后更改用户看到的消息? If the user types "right" twice, the message should be "Think harder? You are in the Lost Forest Go left or right?"如果用户键入“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/")

Storing user progress will be useful存储用户进度将很有用

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/")

How about this:这个怎么样:

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/")

Online demo在线演示

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM