Python Forum
name undefined Coding Error - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: name undefined Coding Error (/thread-24247.html)



name undefined Coding Error - Ewilliam51 - Feb-06-2020

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 Huh
This is the program
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")
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

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



RE: name undefined Coding Error - micseydel - Feb-06-2020

The problem is that you're using Python 2. You should use Python 3 instead.

Note: we can tell you how to make this work for Python 2, but we're not going to unless you absolutely must be using Python 2, since it's been end-of-life'd and we're all trying to move to the better thing anyway.


RE: name undefined Coding Error - Ewilliam51 - Feb-06-2020

Thank you, I just realized I had accidentally download Python 2 and forgot to uninstall it I will make sure to switch back to Python 3