Feb-06-2020, 12:12 AM
I created a program that is supposed to ask the user for a number, tell the user whether the number is odd or even and then ask the user if they want to try another number. I made some sort of error but I honestly don't know what it could be
This is the program
The code works until it asks the user if it wants to try again
when I try to type y or n I get this error

This is the program
1 2 3 4 5 6 7 8 9 10 11 12 13 |
import time while True : number = int ( input ( "Give me a number: " )) time.sleep( 2 ) if number % 2 = = 0 : print ( "This is an even number" ) elif number % 2 ! = 0 : print ( "This is an odd number" ) time.sleep( 2 ) repeat = input ( "Would you like to try another number(y/n):" ) if repeat.strip() = = "n" : break print ( "Okay bye now" ) |
when I try to type y or n I get this error
Error:Traceback (most recent call last):
File "testing.py", line 10, in <module>
repeat = input("Would you like to try another number(y/n):")
File "<string>", line 1, in <module>
NameError: name 'n' is not defined