import random

guessesTaken = 0
my_name = input("Hello, What is your name? ")
difficulty = input("Well, "+ my_name + ". What dificulty would you like ? easy medium or hard? "
if difficulty == easy
    number = random.randint (1,20)
    print ("Okay, " + my_name + ". I am thinking of a number between 1 and 20")
if difficulty == medium
    number = random.randint (1,50)
    print ("Okay, " + my_name + ". I am thinking of a number between 1 and 50")
if diffuculty == hard
    number = random.randint (1,100)
    print ("Okay, " + my_name + ". I am thinking of a number between 1 and 100")                              
while guessesTaken < 6:
    guess = int(input('Take a 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, ' + my_name + '! You guessed my number in ' + guessesTaken + ' guesses!')
if guess != number:
    number = str (number)
    print('Nope. The number I was thinking of was ' + number)

I am a 14 year old student studying python and in this guessing game i would like to know how to create different difficulty levels, i've had a go but i continue to get a syntax error, please help. Thanks in advance.

You need to add colons in your 'if' statements.

'if difficulty == easy:'
etc.

commented: good help +14

I've fixed the unclosed bracket on the difficulty variable, and added colons and im now recieving this error.

Traceback (most recent call last):
  File "C:/Users/MartinStephenTester/Desktop/Python Coding/NewGuessingGame.py", line 5, in <module>
    if difficulty == easy:
NameError: name 'easy' is not defined
>>> 

I've fixed it now , if anyone would like to see what the code now looks like here it is.

import random
easy = random.randint (1,20)
medium = random.randint (1,50)
hard = random.randint (1,100)

guessesTaken = 0
my_name = input("Hello, What is your name? ")
difficulty = input("Well, "+ my_name + ". What dificulty would you like ? easy medium or hard? ")
if difficulty == "easy":
    number = easy
    print ("Okay, " + my_name + ". I am thinking of a number between 1 and 20")
if difficulty == "medium":
    number = medium
    print ("Okay, " + my_name + ". I am thinking of a number between 1 and 50")
if difficulty == "hard":
    number = hard
    print ("Okay, " + my_name + ". I am thinking of a number between 1 and 100")
while guessesTaken < 6:
    guess = int(input('Take a 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, ' + my_name + '! You guessed my number in ' + guessesTaken + ' guesses!')
if guess != number:
    number = str (number)
    print('Nope. The number I was thinking of was ' + number)

I noticed you copied it from a book

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.