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![](https://ecs-static.teamtreehouse.com/assets/views/marketing/shared/community-banner-white-47072046c51352fe6a69f5e691ff5700b28bb11d45197d7bdf066d9ea3f72d0c.webp)
![James Kelley](https://secure.gravatar.com/avatar/dff0c91346eb73d9dd53a1de0660ccce?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
James 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](https://uploads.teamtreehouse.com/production/profile-photos/969492/micro_tool_chess_set_2.jpg)
Steven Parker
230,688 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](https://uploads.teamtreehouse.com/production/profile-photos/7658112/micro_just_I.jpg)
victor E
19,145 Pointsvery likely you did not declare your variable at the beginning before adding or subtracting to it.
![James Kelley](https://secure.gravatar.com/avatar/dff0c91346eb73d9dd53a1de0660ccce?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
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](https://uploads.teamtreehouse.com/production/profile-photos/5900142/micro_jeff_face.jpg)
Jeff Muday
Treehouse Moderator 28,718 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](https://secure.gravatar.com/avatar/a5d16fec61bff0e89ac89c4643394c0c?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
taliarosen
2,492 PointsI think the code you're looking for is tickets_remaining -= tickets_purchased
Jeff Muday
Treehouse Moderator 28,718 PointsJeff Muday
Treehouse Moderator 28,718 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!