Ask coding questions

← Back to all posts
Everything is right, right?
TristanMisja (24)

All the syntax is fine, but it bugs out! Please tell me why and how to fix it!

Answered by potootos (19) [earned 5 cycles]
View Answer
Commentshotnewtop
potootos (19)

I figured it out,
1st is that you wrote radaint on line 9, instead of randint
2nd you need to select all code included in the class game and press TAB and then SHIFT + TAB. How that will help you is that it will get rid of the indentation error the program was throwing. The case might be that you included some 'spaces' instead of 'tabs'.
3rd you need to put an int() statement in front of the input() statement on line 11 of the code because currently what the user inputs is a string, a string cannot be compared using the >, <, symbol because the code does not interpret it as a number. Using the int() statement like so: int(input('enter a number!: ')) will covert the string into an integer (number).
4th you clear the terminal too quickly, and therefore your function doesn't have time to print if the answer is too high or too low. You could fix by altering the time.sleep function to 6 seconds.

FINAL RESULT

import random,sys,os,time
from colorama import Fore

def endFunc():
pass

class Game:
def NumGuess():
x = random.randint(0,10)
while True:
y = int(input("Enter a number!: "))
if y == x:
print("Correct!")
time.sleep(6)
os.system("clear")
endFunc()
elif y < x:
print("Too low!")
time.sleep(6)
os.system("clear")
elif y > x:
print("Too high!")
os.system("clear")
else:
print("Enter a valid number!")

Game.NumGuess()

potootos (19)

@TristanMisja if I answered your question please mark it answered so others will know :D

TristanMisja (24)

@potootos Repl.it is broken :/
Also, something else is wrong D:

TristanMisja (24)

@potootos it says the "try:" is invalid syntax