Pythonで完了する文字推測ゲームがあります。ユーザーが選択できる文字は「a、b、c、および d」です。5 回試行する方法は知っていますが、正しい文字の 1 つを推測したときに、ループを抜け出してプレーヤーを祝福することはできません。
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.')