Question: Write a class Fish, that does the following. it has four attributes: name (string), age (int), weight (float) and alive (bool). age and weight

Write a class Fish, that does the following. it has four attributes:

Write a class Fish, that does the following. it has four attributes: name (string), age (int), weight (float) and alive (bool). age and weight default to 1 and 5.0 if not specified, and alive is always set to True when the fish object is created. . It has an str method that outputs "Fish [name] is [age] years old and is [weight]kg.". The weight is formatted to 2 decimal places. It also has a eat method that given another fish, its own weight increases by 90% of the other fish's weight. It also prints "Fish [name] ate [another fish's name]!". However, if the fish's weight exceeds age 15, then the fish dies from overeating. In that case, it prints out "Fish [name] ate too much and died!". If the given fish is already dead, you should print "Cannot eat dead fish!". If the fish is dead, it will print out "Fish [name] is dead." when trying to print it. It will also print "A dead fish cannot eat!" if it tries to eat. Also, if you are eaten, you are also dead. Note: a fish will never be created that the weight exceeds age *15. Fish("Shark", 5, 30.0) Fish ("Tuna", 2, 20.0) For example: Test shark tuna print(shark) print(tuna) shark.eat(tuna) print(shark) Result Fish Shark is 5 years old and is 30.00kg. Fish Tuna is 2 years old and is 20.00kg. Fish Shark ate Tuna! Fish Shark is 5 years old and is 48.00kg. Fish Tuna is dead. print(tuna) shark Fish("Shark", 5, 70.0) tunal Fish("Tunal", 2, 20.0) tuna2 = Fish ("Tuna2", 2, 20.0) shark.eat(tunal) shark.eat (tuna2) print(shark) print(tuna1) print (tuna2) Fish Shark ate Tuna1! Fish Shark ate too much and died! A dead fish cannot eat! Fish Shark is dead. Fish Tunal is dead. Fish Tuna2 is 2 years old and is 20.00kg.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

Heres the Fish class implementation according to the described behavior python class Fish def in... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!