Just started learning Python and I tried making a "guess the number" game where you set the minimum and maximum numbers yourself, but it gives me errors.
Could anyone tell me how to fix this?
Thanks in advance!
These are the errors I'm getting:
Could anyone tell me how to fix this?
Thanks in advance!
Code
import random
def chanceset():
min_num = int(input("Enter the minimum number here: "))
max_num = int(input("Enter the maximum number here: "))
if max_num > min_num:
print("Thank you! Minimum number set to " + str(min_num) + " and maximum number set to " + str(max_num) + ". Good luck!")
cc = random.randint(min_num, max_num)
game()
else:
print("Maximum number has to be higher than minimum number.")
chance()
def game():
print("")
print("")
pc = int(input("Enter a number between " + min_num + " and " + max_num + "."))
if pc <= max_num and pc >= min_num:
print("The computer's choice is " + cc + ".")
print("Your choice is " + pc + ".")
if cc == pc:
print("Congratulations! You won!")
else:
print("That's too bad, you lost.")
else:
print("Your input must be beween " + min_num + " and " + max_num + ".")
chanceset()These are the errors I'm getting:
Code
Traceback (most recent call last):
File "Desktop/Python/guessthenumber.py", line 26, in <module>
chanceset()
File "Desktop/Python/guessthenumber.py", line 9, in chanceset
game()
File "Desktop/Python/guessthenumber.py", line 16, in game
pc = int(input("Enter a number between " + min_num + " and " + max_num + "."))
NameError: global name 'min_num' is not defined

