4 Replies - 1021 Views - Last Post: 17 January 2014 - 12:51 PM Rate Topic: -----

#1 MK718  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 32
  • Joined: 31-October 13

Weird syntax error

Posted 17 January 2014 - 11:55 AM

Hello guys, I started learning python however when I run this code I'm getting a syntax error, I can't figure out what the problem is.. any help would be greatly appreciated.
# This is a guess the number game.
import random

guessesTaken = 0

print('Hello! What is your name? ')
myName = input()

number = random.randint(1,50)
print('Well, ' + myName + ', I am tihnking of a number between 1 and 50')

while guessesTaken < 6:
    print('Take a guess.')
    guess = input()
    guess = int(guess)

    guessesTaken = guessesTaken + 1

    if guess < number:
        print('Your guess is too low.')

    if guess > number:
        print('Your guess is too high.')

    if guess == number:
        break
if guess == number:
    guessesTaken = str(guessesTaken)
    print('Good job, ' + myName + ' You guessed my number in ' + guessesTaken 'tries!')

if guess != number:
    number = str(number)
    print('Nope, I was thinking of ' + number)
    



Is This A Good Question/Topic? 0
  • +

Replies To: Weird syntax error

#2 jon.kiparsky  Icon User is online

  • Beginner
  • member icon


Reputation: 11040
  • View blog
  • Posts: 18,852
  • Joined: 19-March 11

Re: Weird syntax error

Posted 17 January 2014 - 12:04 PM

What is the error?
Was This Post Helpful? 0
  • +
  • -

#3 andrewsw  Icon User is offline

  • blow up my boots
  • member icon

Reputation: 6544
  • View blog
  • Posts: 26,525
  • Joined: 12-December 12

Re: Weird syntax error

Posted 17 January 2014 - 12:05 PM

You should post the full error message details.

But you are missing a '+' towards the end of this line:
print('Good job, ' + myName + ' You guessed my number in ' + guessesTaken 'tries!')

Was This Post Helpful? 1
  • +
  • -

#4 MK718  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 32
  • Joined: 31-October 13

Re: Weird syntax error

Posted 17 January 2014 - 12:33 PM

I was getting a syntax error, Thank you andresws and I apologize for not posting the message itself, seems like I forgot to ^^
Was This Post Helpful? 0
  • +
  • -

#5 andrewsw  Icon User is offline

  • blow up my boots
  • member icon

Reputation: 6544
  • View blog
  • Posts: 26,525
  • Joined: 12-December 12

Re: Weird syntax error

Posted 17 January 2014 - 12:51 PM

No worries, glad you sorted ;)

Just to note that Python error messages are some of the most helpful of any language, which is why you will always be asked to post them. (They should be posted for any language though.)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1