**Question:**Cant understand Why I get error when I input the number 50 (for example) in my coded guessing game ? PleaseHelå
Repl link: https://replit.com/@patrikgyllhamn/GuessNumber#main.py
code snippet
**Question:**Cant understand Why I get error when I input the number 50 (for example) in my coded guessing game ? PleaseHelå
Repl link: https://replit.com/@patrikgyllhamn/GuessNumber#main.py
code snippet
The input
function returns a string, and for comparison it must be a number. Therefore, you should set the guess
variable not input()
, but int(input())
.
Corrected code:
import random
def generate_number():
return random.randint(1, 100)
def check_guess(guess_num, rand):
if guess > rand:
print("To high...")
elif guess < rand:
print("To Low...")
else:
return True
random_number = generate_number()
print("Welcome 2 the guessing game, guess the right number")
guess = 0
while guess != random_number:
guess = int(input())
if check_guess(guess, random_number):
print("You won the game")
break
I still dont get it - When adding your code i get this error messege
AttributeError: partially initialized module ‘random’ has no attribute ‘randrange’ (most likely due to a circular import)
Thankfull for help
I got the solutions else where - its here
The error you’re encountering, AttributeError: partially initialized module 'random' has no attribute 'randrange' (most likely due to a circular import)
, suggests that there might be an issue with naming conflicts or circular imports in your code.
One way to resolve this issue is to check if you have a file in your project or working directory named random.py
. If such a file exists, it may be conflicting with the built-in random
module.
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.