Question: Python I need to correct an error when the program runs and has nameError for if play _ again in yesList: , this should ask

Python
I need to correct an error when the program runs and has nameError for if play_again in yesList: , this should ask number from user and inform user if too high or too low or if it matches the same number and then ask user if they want to play again, if yes play again generate a new random number and ask user to input a number again. If the answer is no then exit the game and say goodbye.
#Program asks for a number and if you get the number you win
import random
def hello():
print("Hello, welcome to the Guessing Game!")
def goodbye():
print('Goodbye thank you for playing!')
def main():
number = int(input("Please enter a number between 1 to 10: "))
noList: list[str]=["no","n","N","NO"]
yesList: list[str]=["yes","y","Y", "YES"]
hello()
number = int(input("Please enter a number between 1 to 10: "))
number_to_guess = random.randrange(1,11)
while number_to_guess != number:
if number > number_to_guess:
print("Too high")
break
elif number < number_to_guess:
print("Too low")
break
else:
print("Congratulations you got the right number!")
break
print(number)
print(number_to_guess)
play_again = input("Would you like to play again? [y/n]: ")
if play_again in yesList:
main()
else:
goodbye()
main()

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!