我有一个用 Python 完成的字母猜谜游戏。用户可以选择的字母是“a、b、c 和 d”。我知道如何给他们五次尝试,但是当我猜出其中一个正确的字母时,我无法打破循环并祝贺玩家。
g = 0
n = ("a", "b", "c", "d")
print("Welcome to the letter game.\nIn order to win you must guess one of the\ncorrect numbers.")
l=input('Take a guess: ');
for g in range(4):
if l == n:
break
else:
l=input("Wrong. Try again: ")
if l == n:
print('Good job, You guessed one of the acceptable letters.')
if l != n:
print('Sorry. You could have chosen a, b, c, or d.')