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 trial

Python Python Basics All Together Now Gather Information

Anna Shalaginova
Anna Shalaginova
3,160 Points

NameError: name 'A' is not defined when running the code in mac terminal

When I run the code below in my mac terminal, I get this error:

There are 100 tickets remaining. What is your name? A Traceback (most recent call last): File "tickets.py", line 63, in <module> name = str(input("What is your name? ")) File "<string>", line 1, in <module> NameError: name 'A' is not defined

It works fine in the teamtreehouse workspace.

TICKET_PRICE = 10
tickets_remaining = 100

#Output how many tickets are remaining using the ticket_remaining variable

print("There are {} tickets remaining.".format(tickets_remaining))

# Gather the user's name and assign to a new variable

name = str(input("What is your name? "))

# Prompt the user by name and ask how many tickets they would like

num_tickets = input("How many tickets would you like, {}?".format(name))
num_tickets = int(num_tickets)

# Calculate the price (number of tickets multiplied by the price) and assign it to a variable

amount_due = num_tickets * TICKET_PRICE

# Output the price to the screen

print("The total due is ${}".format(amount_due))

Mod Edit: Fixed code formatting. Use backticks [`], generally located on the ~ key, in place of normal single quotes.

1 Answer

rydavim
rydavim
18,813 Points

What version of Python are you using? If you're not sure, you can check using the python -V command.

If you are using Python 2, I believe it eval()s the input values. If this is the case, you could try using raw_input() or switch to Python 3 or later. You may have a later version installed already - trying starting it up with python3 instead of just python.

If that isn't the issue, let me know and we can troubleshoot some more. Happy coding!