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 trialJames Kelley
276 PointsNameError: name "tickets_remaining" is not defined
The portion where I decrement the tickets_remaining keeps returning the above-mentioned error message. I used the placeholder -= shown in the video. I don't know why it keeps returning the error message.
Steven Parker
231,268 PointsFor help with Jeff's suggestions about sharing code, you might want to take a look at this video about Posting a Question, and perhaps also this one about making a snapshot (note: not a "screenshot") of your workspace.
4 Answers
victor E
19,146 Pointsvery likely you did not declare your variable at the beginning before adding or subtracting to it.
James Kelley
276 PointsOkay, I edited my original post and added a link to a screenshot of my workspace. Should I have forked the screenshot?
Jeff Muday
Treehouse Moderator 28,720 PointsThat is a great way to get comments on your code, it is much appreciated!
You almost had it! All we have to do is change 1 line, but that was it. We can definitely build on that.
There are so many ways this can be fixed, but the easiest is to replace tickets_left
with tickets_remaining
. Specifically, the line
tickets_left -= tickets_left
should be
tickets_remaining -= tickets_remaining
was causing your issue. tickets_left
was used before it was initialized.
Your program is working after that.
The next step in writing the program is to put in a looping structure and some conditional logic that will keep your ticket sales from accepting orders for more tickets than are for sale. But I'll leave that fun for you!
Enjoy your Python journey!
taliarosen
2,492 PointsI think the code you're looking for is tickets_remaining -= tickets_purchased
Jeff Muday
Treehouse Moderator 28,720 PointsJeff Muday
Treehouse Moderator 28,720 PointsJames,
We'd have to see your code to make a determination. You can fork a workspace or put your code as a block of an email and we could comment on it.
Usually, a variable name is mistyped, out of scope, or possibly, uninitialized before it is used. Check to see if
tickets_remaining
is given an initial value in your problem.If it isn't paste it into the forum.
best regards!