Jump to content

Python Syntax Error. WHY?!

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
3 replies to this topic

#1
Waffles

Waffles

    Newbie

  • Members
  • Pip
  • 7 posts

import random

again = "yes"

print "\tWelcome to Number Guess 1.2!"

print "\t     XXXX XXXXXX 2010"

while play_again == "yes":

    player_guess = False

    guess_count = 0

    difficulty = 0

    diff_pick = False

    player_name = raw_input("\nWhat is your name?: ")

    print "\nHello,", player_name,"this is a number guessing game!"

    print "\nPick a difficulty:\nEasy(10 guesses)\nMedium(6 guesses)\nHard(4 guesses)"

    diff_pick = raw_input("\nChoose: ")

    diff_pick = diff_pick.lower()

    if diff_pick != False:

        if diff_pick == "easy":

            difficulty = 10

        elif diff_pick == "medium":

            difficulty = 6

        elif diff_pick == "hard":

            difficulty = 2

    print "\nI am thinking of a number between 1 and 100"

    number = random.randrange(100) + 1

    while player_guess != number and guess_count != difficulty:

        player_guess = int(raw_input("Guess a number: "))

        if player_guess > number:

            print "Guess Lower..."

            guess_count += 1

        elif player_guess < number:

            print "Guess Higher..."

            guess_count += 1

    print "\nYEAH! You guessed right!"

    print "YOU WIN!"

    lplay_again = raw_input("Do you want to play again?\nYes or No: "

[COLOR="red"]else:[/COLOR]

    print "See Ya next time!"

raw_input("Press 'Enter' to quit.")

Its just a simple guessing game I wrote to show my buddy an example of Python.

The red text is the syntax error.

Why is this happening? :confused:

#2
dbug

dbug

    Programmer

  • Members
  • PipPipPipPip
  • 155 posts
while loop doesn't accept an else. I think you are missing an 'if' statement comparing the value of lplay_again with 'Yes', and that 'else' corresponds to this missing 'if' (and it must be more indented).

#3
ZekeDragon

ZekeDragon

    Writes binary right handed and hex left handed

  • Moderators
  • 2,103 posts
@dbug: That's incorrect, While loops in Python do accept else statements.

The reason your program is having a syntax error is because your raw_input function call does not have a closing parenthesis. Check it. :)

    lplay_again = raw_input("Do you want to play again?\nYes or No: "
Also, lplay_again will NOT change the contents of play_again!
Wow I changed my sig!

#4
Waffles

Waffles

    Newbie

  • Members
  • Pip
  • 7 posts
BAH!

So it WAS just a typo!

I looked over that block of code over and over and over, but I couldn't see the problem!

BAAAAAAAHHHH!