Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9124297
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T06:32:26+00:00 2026-06-17T06:32:26+00:00

Python 3: Coding hangman from Invent Games with Python. Syntax msg says invalid syntax

  • 0

Python 3:
Coding hangman from “Invent Games with Python.” Syntax msg says “invalid syntax” and highlights print function. I think problem is with the hangman word list and split method. Thanks for your help.

import random
HANGMANPICS = ['''

  +---+
  |   |
      |
      |
      |
      |
      |
=========''', '''


  +---+
  |   |
  O   |
      |
      |
      |
      |
=========''', '''


  +---+
  |   |
  O   |
  |   |
      |
      |
      |
=========''', '''


  +---+
  |   |
  O   |
 /|   |
      |
      |
      |
=========''', '''


  +---+
  |   |
  O   |
 /|\  |
      |
      |
      |
 =========''', '''


  +---+
  |   |
  O   |
 /|\  |
 /    |
      |
      |
=========''', '''


  +---+
  |   |
  O   |
 /|\  |
 / \  |
      |
      |
=========''']


words = '''ant baboon badger bat bear beaver camel cat clam
cobra cougar coyote crow deer dog donkey duck eagle ferret
fox frog goat gooose hawk lion lizard llama mole monkey
moose mouse mule newt otter owl panda parrot pigeon python
rabbit ram rat raven rhino salmon seal shark sheep skunk
sloth snake spider stork swan tiger toad trout turkey
turtle weasel whale wolf wombat zebra'''.split()



def getRandomWord (wordList):
    wordIndex = random.randint(0, len(wordList) -1)
    return wordList[wordIndex]


def displayBoard (HANGMANPICS, missedLetters, correctLetters, secretWord):
    print(HANGMANPICS[len(missedLetters)]
    print()           #this print statement is highlighted w/invalid syntax msg

    print('Missed letters:', end=' ')
    for letter in missedLetters:
    print(letter, end=' ')
    print()

    blanks = '_' * len(secretWord)

for i in range(len(secretWord)):    #replaces blanks w/correctly guessed ltrs
    if secretWord[i] in correctLetters:
        blanks = blanks[:i] + secretWord[i] + blanks[i + 1:]

for letter in blanks:               #show secret word w/spaces between ltrs
    print(letter, end=' ')

print()
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T06:32:27+00:00Added an answer on June 17, 2026 at 6:32 am

    You forgot a closing parenthesis on the line before the one with just print() on it:

    print(HANGMANPICS[len(missedLetters)]  # Note the missing `)` here
    

    When you get a unexplained syntax error in Python, check the preceding line; Python expected to find more arguments to the print() function there, and the next line violated that expectation.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

#!/usr/bin/env python # -*- coding: utf8 -*- print 私 print u私 the result: ç§
#!/usr/bin/env python # -*- coding: UTF-8 -*- # enable debugging import cgitb cgitb.enable() print
#!/usr/bin/env python # -*- coding: utf-8 -*- from sqlalchemy import create_engine connection = create_engine('mysql://user:passwd@localhost:3306/db').connect()
#!/usr/bin/python # -*- coding: iso-8859-1 -*- import Tkinter import twitter class simpleapp_tk(Tkinter.Tk): def __init__(self,parent):
#!/usr/bin/python # -*- coding: iso-8859-1 -*- import Tkinter class simpleapp_tk(Tkinter.Tk): def __init__(self,parent): Tkinter.Tk.__init__(self,parent) self.parent=parent
While coding python I'm using only 2 spaces to indent, sure PEP-8 really recommend
I am new to coding python. I am hoping to modify this code to
I am 2 days old with python and coding in general, I have been
I started coding in python a week ago, it is my mistake i started
I am coding a python (2.6) interface to a web service. I need to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.