Objects – Intro Activity

1)
Make a class named Creature.

class Creature:
    pass

This doesn’t do anything specific yet, because “pass” just means do nothing.

2) Now, in the main body of your code, create some Creature objects like this:

x = Creature()
abc = Creature()

3) You can give the creatures some attributes.

x.height = 20
abc.height = 7

4) Print each Creature, then print the attributes you gave them.

print(x)
print(abc)
print(x.height)
print(abc.height)

5) Change the attribute of one of them. Notice that the other creature still has its own value of the attribute.

x.height = 59
print(x.height)
print(abc.height)

6) Add the objects to a list.

creatures = [x, abc]

7) Print each creature in the list.

for c in creatures:
    print(c)

8) That wasn’t very useful. Instead, print the height of each creature.

for c in creatures:
    print(c.height)

9) Add 5 more Creature objects to your list.

for i in range(5):
    temp = Creature()
    temp.height = 10
    creatures.append(temp)

10) Now use another loop and print the height of every Creature. Are there 5 more creatures?

11) Give each creature a name attribute and make up different names for each one.
Examples

creatures[0].name = "Gary"

12) Use a loop, and print a sentence that says the name and height of each Creature.