I wrote a code after watching a tutorial, i keep getting syntax errors, please help me debug it :D

import random

top_of_range = input("type a number ")
if top_of_range.isdigit():
top_of_range = int(top_of_range)

if top_of_range <= 0:
print(“type a number higher than 0 next time.”)
quit()
else:
print(“type a number next time.”)
quit()

random_number = random.randit(0, top_of_range)

while True:
user_guess = input("type a number ")
if user_guess.isdigit():
user_guess = int(user_guess)
else:
print(“type a number next time”)
continue

if user_guess == random_number:
print(“you guessed it right”)
break

elif user_guess > random_number:
print(“you are above the number”)
else:
print(“you are below the number”)

Hi,
You’ve misspelled randint
Some of your quote marks showed up differently and I had to retype them - which sometimes happens when you copy code from different editors.
Other than that, assuming it’s all indented correctly, it seems to work correctly when I try it.

Hope that helps

import random

top_of_range = input("type a number ")
if top_of_range.isdigit():
  top_of_range = int(top_of_range)

  if top_of_range <= 0:
    print("type a number higher than 0 next time.")
    quit()
else:
  print("type a number next time.")
  quit()

random_number = random.randint(0, top_of_range)

while True:
  user_guess = input("type a number ")
  if user_guess.isdigit():
    user_guess = int(user_guess)
  else:
    print("type a number next time")
    continue

  if user_guess == random_number:
    print("you guessed it right")
    break
  elif user_guess > random_number:
    print("you are above the number")
  else:
    print("you are below the number")
1 Like

Thank you! I appreciate it :smiley:

1 Like