0

I am using a book to learn programming and I started learning about objects and classes. I created my class:

class Giraffes:
    def __init__(self, spots):
        self.giraffe_spots = spots

I then created Ozwald with a number for his spots:

ozwald = Giraffes(75)

It then gives me an error like this:

Traceback (most recent call last):
  File "<pyshell#4>", line 1, in <module>
    ozwald = Giraffes(75)
 File "<pyshell#3>", line 3, in __init__
   self.giraffe_spots = spot
NameError: name 'spot' is not defined

What am I doing wrong? I've done exactly what my book is telling me to do.

4
  • 1
    this error message does not come from that code. there was an 's' missing in the original code (spot vs spots) and you must have fixed it. see the line where it tells you self.giraffe_spots = spot, it is not the same line that you posted Commented Mar 26, 2015 at 0:29
  • @JulienSpronck Where? Commented Mar 26, 2015 at 0:30
  • self.giraffe_spots = spot should be self.giraffe_spots = spots Commented Mar 26, 2015 at 0:31
  • @Marcin Oooooohhhhhh. Well now I feel stupid 😩. Thanks for the help! Commented Mar 26, 2015 at 0:34

1 Answer 1

3

This line:

self.giraffe_spots = spots

is written as this:

self.giraffe_spots = spot

wherever you are actually running it.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.