このコードの前提は、最大3回の試行で名前を要求することです。whileループへのif文の追加
password = 'correct'
attempts = 3
password = input ('Guess the password: ')
while password != 'correct' and attempts >= 2:
input ('Try again: ')
attempts = attempts-1
if password == 'correct': #Where the problems begin
print ('Well done')
私は、「よくできました」を返す最初の試行でしか正しいパスワードを入力できません。他の2つの試みでは、「もう一度やり直してください」と返されます。どのような試みでも入力した場合、どのようにして正常に戻ることができますか?
FYI、 'attempts = attempts-1'は' attempts-= 1'としてより簡単に書くことができます – Alexander