I've looked up the continue
key word but I'm still not quite understanding what role its playing in the if
statements. I'm assuming this says continue on and treats the elif
like an if
statement, but I'm not sure why not just use an if
statement instead of an elif
statement with continue
.
If that is the case, all those those conditional statements need to be checked no matter if
is true
or false
. Why not just use an if
statement instead of an elif
?
If I'm understanding continue
correctly, what is the reason for the last one because a new if
statement is right after it? Wouldn't it naturally just continue to that if
statement?
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))