Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

Need help with some Python code


MCADAMS
 Share

Recommended Posts

I'm learning programming for the first time with Python, trying to make a random number game. I have this:

```
#Self-written 'Guess the Number' game
import random

guessesTaken = 0

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

number = random.randint(1, 20)
print('Ok, ' + myName + '. I am thinking of a number between 1 and 20\. Guess.')

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

    guessesTaken = guessesTaken + 1

    if guess < number:
          print('Too low!')

    if guess > number:
          print('Too high!')

    if guess == number:
        break

if guess == number:
    guessesTaken = str(guessesTaken)
    print('Congratulations! You guessed the number in ' + guessesTaken + ' guesses!'

if guess != number:
    number = str(number)
    print('Sorry, the number we were looking for was ' + number)

```
When I run it I get "invalid syntax" and it points to the colon after
```
if guess != number:

```
I've double checked the code I'm referencing and they're identical it seems. Any help?
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...