Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
name undefined Coding Error
#1
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
Reply
#2
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.
Reply
#3
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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Coding error. xflyerwdavis 2 531 Oct-07-2023, 07:08 PM
Last Post: deanhystad
  Coding error. Can't open directory EddieG 6 1,128 Jul-13-2023, 06:47 PM
Last Post: deanhystad
  Coding Error EddieG 2 547 Jul-09-2023, 02:59 AM
Last Post: EddieG
  undefined function error JonWayn 5 1,457 Sep-11-2022, 03:38 AM
Last Post: JonWayn
  Undefined Led_Zeppelin 4 1,424 Aug-02-2022, 11:57 AM
Last Post: buran
  ImportError: /home/pybind11_example.cpython-37m-x86_64-linux-gnu.so: undefined symbol chaitra 2 5,125 Feb-03-2021, 05:14 AM
Last Post: chaitra
  python coding error isntitzee 1 2,214 Oct-17-2020, 06:30 AM
Last Post: buran
  Coding error- Not sure where I have put error markers against the code that is wrong Username9 1 1,739 Sep-28-2020, 07:57 AM
Last Post: buran
  coding error iro a menu Rollo 2 2,099 Sep-27-2020, 04:17 PM
Last Post: deanhystad
  Adafruit LIS3DH coding error FitDad73 1 2,010 Aug-30-2020, 01:37 AM
Last Post: bowlofred

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020