Как изменить сообщение, которое видит пользователь после двух попыток - PullRequest
0 голосов
/ 26 мая 2020

Я понимаю, что этот вопрос может быть тривиальным для большинства пользователей, но я изо всех сил пытаюсь найти подход после нескольких часов поиска в Google.

Как изменить сообщение, которое видит пользователь после 2 попыток? Если пользователь дважды набирает «вправо», должно появиться сообщение: «Подумайте еще! Вы находитесь в затерянном лесу 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/")

Ответы [ 2 ]

0 голосов
/ 26 мая 2020

Как насчет этого:

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

Онлайн-демонстрация

0 голосов
/ 26 мая 2020

Будет полезно запоминание прогресса пользователя

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/")
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...