Darkar2045
Darkar2045

Reputation: 21

Class and object error

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.

Upvotes: 0

Views: 50

Answers (1)

Joshua Grigonis
Joshua Grigonis

Reputation: 768

This line:

self.giraffe_spots = spots

is written as this:

self.giraffe_spots = spot

wherever you are actually running it.

Upvotes: 3

Related Questions