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 Object-Oriented Python (retired) Hack-n-Slash The Final Push

name 'roll' is not defined

the terminal is saying that the roll is not defined even though i wrote they same code as the video explained and checked the combat.py fie more than one time and nothing has seemed to happend. this is my code if you want to look at it: https://drive.google.com/drive/folders/0B2LZB_NY3It-amx4OE1yNWREVzA?usp=sharing

I have a screenshot of the output of the program on my drive

jag
jag
18,266 Points

It's better if you post and host your code in workspaces that way we can easily see and modify if need be.

  1. Go to: https://teamtreehouse.com/workspaces
  2. Click on "New +"
  3. Name workspace
  4. Select environment "Python"
  5. Create

Since workspaces preview only lives temporarily create a snapshot.

  1. Click snapshot (First icon on top right corner)
  2. Share snapshot link https://w.trhou.se/rpuj2yjpwg
Chris Freeman
Chris Freeman
Treehouse Moderator 68,423 Points

Can you please post the stack trace from the error message?

This will show what the code was doing during the error.

1 Answer

Steven Parker
Steven Parker
229,670 Points

:point_right: Your code is a bit different from the code in the video.

As shown in the video "Dry", the attack routine first places a random number in a variable named "roll". But the same method in your version of combat.py places the random number in a variable named "attack". So when the next statement tries to reference the variable using the name "roll", it does not exist (and is therefore "not defined").