Write a class Fish, that does the following. it has four attributes: name (string), age (int),...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
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. 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.
Expert Answer:
Answer rating: 100% (QA)
Heres the Fish class implementation according to the described behavior python class Fish def in... View the full answer
Related Book For
Income Tax Fundamentals 2013
ISBN: 9781285586618
31st Edition
Authors: Gerald E. Whittenburg, Martha Altus Buller, Steven L Gill
Posted Date:
Students also viewed these programming questions
-
CANMNMM January of this year. (a) Each item will be held in a record. Describe all the data structures that must refer to these records to implement the required functionality. Describe all the...
-
Managing Scope Changes Case Study Scope changes on a project can occur regardless of how well the project is planned or executed. Scope changes can be the result of something that was omitted during...
-
The CEO of Amazon, has publicly questioned the advisability of granting patents for business processes such as his companys 1-Click ordering process. Do such patents put a chilling effect on the...
-
Name the following polymer(s) that would be suitable for the fabrication of cups to contain hot coffee: polyethylene, polypropylene, poly(vinyl chloride), PET polyester, and polycarbonate. Why?
-
Does adoption of the credit-subtraction method require the use of invoices for each transaction?
-
Assume the expected inflation rate in China to be 4.5 percent. If the current real rate of interest is 6.5 percent, what is the nominal rate of interest?
-
David Mashley teaches two undergraduate statistics courses at Kansas College. The class for Statistics 201 consists of 7 sophomores and 3 juniors. The more advanced course, Statistics 301, has 2...
-
4. The atomic numbers of elements, U, V, W and X are 13, 14, 16 and 17 respectively. Which one of the elements will react with oxygen to form an ionic compound? (Atomic number of oxygen is 8) X A. B....
-
A public interest group was planning to make a court challenge to auto insurance rates in one of three cities: A (Atlanta), B (Baltimore), or C (Cleveland). The probability that it would choose...
-
Divide 8(cos0.8 + i sin0.8) by 4(cos0.2 + i sin0.2).
-
What is Respiration? Explain in detail
-
Explain the procedure of testing research hypotheses
-
As of the 27 th December 2020, the Kenya Shilling continued it's down-slide spiral against the world's major currencies. On a Year To Date (YTD) basis, the shilling depreciated by 7.4% against the...
-
Solid magnesium selenide has a crystal structure with the cubic unit cell pictured below, where the Se ions are represented as green spheres. The Se ions can be described as being What is the...
-
You need to make presentation on Africas New Generation of Innovators
-
What is the back work ratio? What are typical back work ratio values for gas-turbine engines?
-
A positively charged particle moves from point I to point 2. As it does, its electric potential energy? A. Increases. B. Decreases. C. Stays the same. 102
-
Rank in order, from largest to smallest, the potential differences V 12 , V 13 , and V 23 between points 1 and 2, points l and 3, and points 2 and 3.
-
Which set of equipotential surfaces matches this electric field? 111
Study smarter with the SolutionInn App