I am writing this code while learning from online videos. The issue as after running the code I am getting errors with the last else indentation and the print("string",end = "")
. I just can't figure out the end error that keeps popping.
import random
# Make a list of words
words = ['apple','banana','orange','coconut','strawberry','lime','grapefruit','lemon','kumquat', 'blueberry','melon']
while True:
start = input("Press enter/return to start, or enter Q to quit")
if start.lower() == 'q':
break
# Pick a Random Number
secret_word = random.choice(words)
bad_guesses = []
good_guesses = []
while len(bad_guesses) < 7 and len(good_guesses) != len(list(secret_words)):
# Draw guesses letters, spaces and strikes
for letter in secret_word:
if letter in good_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 single letter !")
continue
elif guess in bad_guesses or guess in good_guesses:
print("You've already guessed that letter !")
continue
elif not guess.isalpha():
print("You can only guess letters !")
continue
if guess in secret_word:
good_guesses.append(guess)
if len(good_guesses) == len(list(secret_word)):
print("YOU WIN !! The word was{}".format(secret_word))
break
else:
bad_guesses.append(guess)
else:
print("You didn't guess it! My secret word was {}".format(secret_word))
This is the error I am getting:
line 17 print(letter, end = "") ^ SyntaxError: invalid syntax Process finished with exit code 1
And regarding the Python version I am trying on both 2.7 and 3.0.
When I removed the end = ""
the program ran , but broke on return.