Hello !can anyone tell me why this code is not runnin?

can any one tell me why this code is not running?

import random
def guess(x):
random_number = random.randint(1,x)
guess = 0
while guess != random_number:
guess = int(input(“Enter your guess number:”)
if guess < random_number:
print(“Too low”)
elif guess > random_number:
print(“Too high”)

print("congratirations")

guess(10)

hi Patrick,
I think it is due to missing indentation after you specify def, as well as after the while clause.
Try this one, it worked for me. Also, you might want ot add a break clause, so that the plaer can quit in case.

import random

def guess(x):

random_number = random.randint(1, x)

guess = 0

while guess != random_number:

    guess = int(input(" enter your guess number: "))

    if guess < random_number:

        print("too low")

    elif guess > random_number:

        print("too high")

    elif guess == "q":

        break

    else:

        print("congrats")

guess(10)

good luck!

1 Like