Python Python Basics All Together Now Gather Information

Anna Shalaginova
Anna Shalaginova
3,078 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
MOD
rydavim
Treehouse Moderator 18,083 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!