Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Python You are now the proud owner of a virtual pet a cute, green frog that leads a simple, yet somehow busy life. You will
Python
You are now the proud owner of a virtual pet a cute, green frog that leads a simple, yet somehow busy life. You will write some code that updates the frog's mood as he (or she) engages in certain activities. Write a function frog ) that takes the following arguments, in this order: mood: a positive integer that indicates the starting mood of the frog. A higher value indicates a happier mood. actions: a list of strings containing some combination of eat', 'work'. 'play' and 'read Throughout the day the frog eats, works, plays and reads books. These actions affect the frog in different ways If the action is 'play, then add 3 to the frog's current mood. If the action is , eat, and the frog's current mood is at least 50% of his starting mood, then add 1 to the frog's current mood. If the action is , eat, and the frog's current mood is less than 50% of his starting mood, then subtract 2 from the frog's current mood. If the action is , read, and the frog's current mood is at least 75% of his starting mood, then subtract 3 om the frog's current mood. If the action s , read, and the frog's current mood is less than 75% of his starting mood, then subtract 4 from the frog's current mood. If the action is 'work', then subtract 5 from the frog's current mood. Regardless of the frog's mood, any action reduces his mood by 1 If at any time the frog's mood becomes zero or negative, the function stops performing actions and returns 0 Otherwise, the function processes the entire list of actions and returns the frog's final mood. Examples Function Call rog (44, ['eat', 'play frog (16, 'playeat' 'work frog (27, 'play',eat', 'read, 'play', read,read, work', 'read, eat'eat work', WOrk', 'work' frog (41, ['play','work', 'eat'play frog (23, ['work', 'play', 'eat',read', 'work', read', play) frog (50, ['read, eat, 'eat','read, work', 'read', wor frog (10, 'eat, read', work',eat, 'read', 'read', read', work') frog (38, 'play','eat', work', 'play', 'eat,work, read', play,play, work','read', work' frog (7,'work', 'play play read',work') frog (24, 'work', 'play',eat' Return Value 4 6 12 39 25 13 20 You are now the proud owner of a virtual pet a cute, green frog that leads a simple, yet somehow busy life. You will write some code that updates the frog's mood as he (or she) engages in certain activities. Write a function frog ) that takes the following arguments, in this order: mood: a positive integer that indicates the starting mood of the frog. A higher value indicates a happier mood. actions: a list of strings containing some combination of eat', 'work'. 'play' and 'read Throughout the day the frog eats, works, plays and reads books. These actions affect the frog in different ways If the action is 'play, then add 3 to the frog's current mood. If the action is , eat, and the frog's current mood is at least 50% of his starting mood, then add 1 to the frog's current mood. If the action is , eat, and the frog's current mood is less than 50% of his starting mood, then subtract 2 from the frog's current mood. If the action is , read, and the frog's current mood is at least 75% of his starting mood, then subtract 3 om the frog's current mood. If the action s , read, and the frog's current mood is less than 75% of his starting mood, then subtract 4 from the frog's current mood. If the action is 'work', then subtract 5 from the frog's current mood. Regardless of the frog's mood, any action reduces his mood by 1 If at any time the frog's mood becomes zero or negative, the function stops performing actions and returns 0 Otherwise, the function processes the entire list of actions and returns the frog's final mood. Examples Function Call rog (44, ['eat', 'play frog (16, 'playeat' 'work frog (27, 'play',eat', 'read, 'play', read,read, work', 'read, eat'eat work', WOrk', 'work' frog (41, ['play','work', 'eat'play frog (23, ['work', 'play', 'eat',read', 'work', read', play) frog (50, ['read, eat, 'eat','read, work', 'read', wor frog (10, 'eat, read', work',eat, 'read', 'read', read', work') frog (38, 'play','eat', work', 'play', 'eat,work, read', play,play, work','read', work' frog (7,'work', 'play play read',work') frog (24, 'work', 'play',eat' Return Value 4 6 12 39 25 13 20Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started