Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

To be done in Python 3.0 Question 3 (9 points): Purpose: To practice recursion on a problem that can be split into parts Degree of

To be done in Python 3.0image text in transcribedimage text in transcribedimage text in transcribed

Question 3 (9 points): Purpose: To practice recursion on a problem that can be split into parts Degree of Difficulty: Moderate Aspiring pokemon trainer Ash Ketchum has caught quite a few pokemon. In order to keep them healthy. he regularty feeds them vitamins. However, the vitamins are usually bigger than what a pokemon can swallow in one bite, and so when Ash's pokemon team is given a vitamin, they will break it apart into pieces that are small enough for them to eat Sometimes, though, the vitamin is So big, that the pokemon have to break it apart more than once! Here is how the process works: If the vitamin's weight is less than or equal to 01 grams, it is small enough to eat, and doesn't need to be broken. Thus, there is 1 edible piece for 1 pokemon. Otherwise, the pokemon will team up to smash the vitamin into pieces of equal weight. The number of new pieces seems to be random (the pokemon can be a bit excitable), either 2, 3. or 4, but the weight of each piece is the same (one-half, one-third or one-quarter of the previous piece). The pokemon will then break each of these pieces again until they are small enough to swallow. For example, suppose the initial vitamin weighed O.6 grams. The pokemon break it once, and we randomly determine that the vitamin breaks into 2 parts (each part weighs 0.3 grams). The pokemon break the first 0.3 gram piece. which breaks into 3 pieces. Since these pieces will each weigh O.1 grams, they are now edible, so we have 3 edible pieces so far. The pokemon will then break the second 0.3 gram piece this time, it breaks into 2 parts, each of which weighs 0.15 grams, which are still too large to eat. The pokemon break each of these parts again; the first breaks into 3 parts, each weighing O.05 grams, so we have 3 more pieces. The second breaks into 4 parts, each weighing 0.0375 grams, so that's another 4 pieces. There are no longer any pieces larger than O1 grams, so the total number of edible pieces is 3 3+4-10 pieces So in this case. 10 different pokemon are able to get their vitamin dosage from a single, original 0.6 gram vitamin Tracing through the problem like in the paragraph above is exhausting! But if you bring yourself to trust in the power of recursion, solving this problem is not hard at all For this question, your task is to write a recursive program that will calculate how many edible vitamin pieces are made whenever a pokemon team is given a vitamin that weighs W grams

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

SQL For Data Science Data Cleaning Wrangling And Analytics With Relational Databases

Authors: Antonio Badia

1st Edition

3030575918, 978-3030575915

More Books

Students also viewed these Databases questions