Fish in the water

Report a typo

The class Fish stores information about all the fish in some aquarium. One of the class attributes is n_fish which corresponds to the number of fish that have been created (and are now in the aquarium).

In the code below, you can see that there's greg, the only fish that has been created so far. Update the value of n_fish in the correct way.

Remember that integer is an immutable type and class attributes of this kind have to be accessed through the class itself so that changes affect all instances of the class.

Write a program in Python 3
class Fish:
place = "aquarium"
n_fish = 0 # number of fish in the aquarium

def __init__(self, name, kind):
self.name = name
self.kind = kind


greg = Fish("Greg", "guppy")
___

Create a free account to access the full topic