Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Python 3 Recursion Question 1 Purpose: To practice recursion with a simple example Degree of Difficulty: Easy The evil Team Rocket has invented an incredible

Python 3 Recursion Question 1

image text in transcribed

image text in transcribed

Purpose: To practice recursion with a simple example Degree of Difficulty: Easy The evil Team Rocket has invented an incredible new space-ship! The ship works as follows: If the distance to the destination is greater than 1 meter, the ship will 'fold space and jump to a position exactly half way to the destination. It takes exactly one minute to perform this process Any distance of 1 meter or less will take exactly one minute, using normal impulse rockets For example, if the ship has to travel 10 meters, it will jump 5 meters after the first minute, 2.5 meters the second minute, 125 meters the 3rd minute, and 0.625 meters the fourth minute. Finally. the remaining 0.625 meters takes one more minute. Thus the total time to travel 10 meters is 5 minutes. (That seems very slow, and it is for small distances, the true value of this method only reveals itself for large distances.) Write a recursive function called spaceTime() that calculates the time needed for Team Rocket's new ship to travel a given distance (in meters). In the same file, write code that asks the user for a distance in meters (console input), and then calls your spaceTime ) function to calculate the time required to travel the given distance Test your function out on all of the following examples Distance from Team Rocket's base to the nearest Poke-Stop : 37 meters . Distance for a round-trip around the entire planet earth: 40075000 meters Average distance between our earth and our sun: 1.49e11 meters (about 150 million km) Approximate distance between the sun and the closest star: 4.0e16 meters (about 4 light-years) Size of the observable universe: 8.8e26 meters (about 93 Giga-light-years) Sample Run Here is an example execution of the required program Team Rocket 's drive requires - 7 minutes to trave1 37 meters to the nearest Poke Stop - 27 minutes to travel 40075000.0 meters for a round - trip around the earth -39 minutes to travel 149000000000.0 meters from our earth to our sun - 57 minutes to travel 4e+16 meters from our sun to the nearest star - 91 minutes to travel 8.8e+26 meters across the observable universe WOW, IS TEAM ROCKET EVER BLASTING OFF AGAIN!! Your console output doesn't have to look exactly like the above. Copy/paste your output for all of the examples above into a document called a7q1_output.txt for submission

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

Question

305 mg of C6H12O6 in 55.2 mL of solution whats the molarity

Answered: 1 week ago

Question

=+industrial action Under what circumstances can unions strike?

Answered: 1 week ago

Question

=+What forms of industrial action are common?

Answered: 1 week ago