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 trialGottfried Rautenbach
746 PointsI'm getting a NameError, but I did define the relevant variable
I'm receiving this error:
Traceback (most recent call last):
File "masterticket.py", line 10, in <module>
while ticket_balance > 0:
NameError: name 'ticket_balance' is not defined
BUT
my code includes the following, in which "ticket_balance" is defined:
# If they want to proceed # print out "SOLD!" if decision.lower() == "yes": print ("SOLD!") ticket_balance -= number_of_tickets
else:
print("Thank you anyways, {}!".format(user_name))
What am I missing?
1 Answer
Seth Kroger
56,413 Pointsticket_balance -= number_of_tickets
uses the "subtract from" shorthand. It needs ticket_balance to exist first to subtract from it. It doesn't define ticket_balance.