continue
キーワードを検索しましたが、まだif
ステートメントでどのような役割が果たしているのかはまだ分かりません。私はこれがと続けるとを続行し、elif
の文をif
のように扱いますが、elif
の文の代わりにif
の文を使用するのはどうしてわかりませんか?continue
です。誰かがif文でcontinueキーを説明できますか?
このような場合は、if
がtrue
またはfalse
であるにもかかわらず、すべての条件文をチェックする必要があります。 elif
の代わりにif
文を使用するだけではどうですか?
私がcontinue
を正しく理解している場合、新しいif
文がその直後にあるため、最後の理由は何ですか?それは自然にちょうどそれを続けるだろうif
声明?
while True:
start= input('Press q to quite, enter any other key to start')
if start.lower()=='q':
break
#pick a random words
word=random.choice(words)
wrong_guesses=[]
right_guesses=[]
while len(wrong_guess) < 7 and len(right_guesses) != len(word)
#draw spaces
for letter in word:
if letter in right_guesses:
print(letter, end='')
else:
print('_', end='')
print('')
print('strikes: {}/7'.format(len(bad_guesses))
print('')
#take guess
guess= input('guess a letter: ').lower()
if len(guess) != 1:
print('You can only guess a sinlge letter!')
#what is this>>> continue
elif guess in wrong_guesses or guess in right_guesses:
print('you\'ve already guessed that letter!')
continue
elif not guess.isalpha():
print('you can only guess letters!')
#what is this>>> continue
if guess in word:
right_guesses.append(guess)
if len(right_guesses)==len(list(word)):
print('You win! The word was {}'.format(list(word))
break
else:
wrong_guesses.append(guess)
else:
print('you didnt guess it! My secret word was {}'.format(word))
continueステートメントは、外部ループを参照し、ifステートメントではありません。 –
'continue'は' while'ループの次の反復反復にあなたを直接送ります(そうでない場合は何も実行されません) – Julien