[Python] Word Guessing Game in Python?

Discussão em 'Python' iniciado por Stack, Junho 29, 2025.

  1. Stack

    Stack Membro Participativo

    I'm in a basic programming class and I'm a bit stuck working on this game. The idea was to create a simple word-guessing game, where the computer would choose a random word and you would attempt to guess first some letter in the word, then the word itself after 5 tries. I've gone through multiple times and I still get an error of "Invalid Syntax" when I attempt to run the module. I'm a bit dyslexic when it comes to programming languages, so maybe there's something I'm overlooking? I would appreciate it if someone out there could offer a bit of help!

    #Word Guessing Game
    #Computer picks a random word
    #Player tries to guess it
    #computer only responds with yes or no

    import random

    tries = 0

    print "Welcome to the word game!"
    print "\nI'm going to think of a word and you have to guess it!"
    print "\nGuess which letters are in the word, then you have to guess the whole thing!"
    print "\nGood luck!"

    WORDS = ("follow", "waking", "insane", "chilly", "massive",
    "ancient", "zebra", "logical", "never", "nice")

    word = random.choice(WORDS)

    correct = word
    length = len(word)
    length = str(length)

    guess = raw_input("The word is " + length + " letters long. Guess a letter!: ")

    while tries < 5:
    for guess in word:
    if guess not in word:
    print "Sorry, try again."
    else:
    print "Good job! Guess another!"

    tries = tries + 1 #*

    if tries = 5:
    final = raw_input ("Try to guess the word!: ")

    if final = correct:
    print "Amazing! My word was ", word, "!"

    else:
    print "Sorry. My word was ", word, ". Better luck next time!"

    raw_input("\n\nPress enter to exit")


    It should also be noted that the problems occurred after the end of the "while tries" block, when I attempted to specify the limits of the "tries" variable. I've worked with it before in a random number game, but for some reason it didn't work properly here. I would greatly appreciate some help! It should also be noted that I run on a rather outdated version of Python, some variation of 2.0, I believe.

    Continue reading...

Compartilhe esta Página