I am new and trying to create a simple "guess the number game":
import random
class Randgame :
def __init__(self):
pass
def restart(self):
response = input("Type Yes To Play Again!").lower()
if response == "yes":
self.play()
else:
print("Thanks for playing!")
pass
def play(self):
guess = int(input("What's your guess?"))
num = random.randint(0, 10)
if guess == num:
print("Correct!")
else:
print("Nope!")
self.restart()
fun = Randgame()
fun.play()
All is well until I get to the restart() method. If I type "yes" into the console I get this response:
NameError: name 'yes' is not defined
I cannot figure this out to save my life and I don't know what to look up. Please help!
input()accepted Python expressions, rather than strings. If for some strange reason you cannot upgrade to a Python version that's actually still supported, you need to replace it withraw_input()everywhere you use it.