Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialMaximillion Archibald
1,585 Pointscode only working in treehouse workspace?
It worries me that this code works fine in the treehouse workspace, but if you try it in atom and terminal proper, it returns 'NameError" when attempting to take the user name, and take the answer to "would you like to proceed?"
Maximillion Archibald
1,585 PointsHI Megan, thanks for the reply. Here's my code - working fine in treehouse, but still no in terminal.
''''tickets_remaining = 100 TICKET_PRICE = 10
while tickets_remaining >= 1 :
name = input("Hello, welcome to ticketmaster. What is your name? ")
tickets = input("How many tickets would you like, {}? ".format(name))
try:
tickets = int(tickets)
if tickets > tickets_remaining :
print("Sorry, there is only {} tickets remaining".format(tickets_remaining))
quit()
except ValueError as err: print("Sorry, try again {}".format(err))
else:
owed = TICKET_PRICE * tickets
amount_of_tickets = tickets_remaining - tickets
print("That will be {} dollars".format(owed))
should_proceed = input("Do you want to proceed? Y/N ")
if should_proceed == "n" :
print("Thanks Anyway")
quit()
else:
print("SOLD, Thanks!")
tickets_remaining = amount_of_tickets
print("There are {} tickets remaining".format(amount_of_tickets))
print("Tickets are sold out, sorry")'''
Maximillion Archibald
1,585 Pointsand heres the error from terminal:
File "hello.py", line 27, in <module> should_proceed = input("Do you want to proceed? Y/N ") File "<string>", line 1, in <module> NameError: name 'y' is not defined
1 Answer
Megan Amendola
Treehouse TeacherI ran this locally and everything worked just fine. Have you tried a different IDE in case it's a setting in Atom?
tickets_remaining = 100
TICKET_PRICE = 10
while tickets_remaining >= 1 :
name = input("Hello, welcome to ticketmaster. What is your name? ")
tickets = input("How many tickets would you like, {}? ".format(name))
try:
tickets = int(tickets)
if tickets > tickets_remaining :
print("Sorry, there is only {} tickets remaining".format(tickets_remaining))
quit()
except ValueError as err:
print("Sorry, try again {}".format(err))
else:
owed = TICKET_PRICE * tickets
amount_of_tickets = tickets_remaining - tickets
print("That will be {} dollars".format(owed))
should_proceed = input("Do you want to proceed? Y/N ")
if should_proceed == "n" :
print("Thanks Anyway")
quit()
else:
print("SOLD, Thanks!")
tickets_remaining = amount_of_tickets
print("There are {} tickets remaining".format(amount_of_tickets))
print("Tickets are sold out, sorry")
Maximillion Archibald
1,585 Pointsaha, i was running python 2, so it expected raw_input, instead of input. got er. thanks for the help.
Megan Amendola
Treehouse TeacherMegan Amendola
Treehouse TeacherHi! I ran the code locally and had no problems. You can post your code here so we can take a look and see if there's a mistake causing the error.