Question

Question 1 10 points): Purpose: To practice recursion with a simple example Degree of Dificuity 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 Told space and jump to a position exactly half way to the destination It takes exactly one minute to perform this process e 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 wil jump 5 meters after the first minute, 25 meters the second minute, 125 meters the 3rd minute, and 0625 meters the fourth minute Finally the remaining 0625 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 tself for large distances) Write a recursive function called spaceTime ) that calculates the time needed for Team Rockets new ship to travel a given distance in meters) In the same file. wite 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 e Distance from Team Rockets 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 149e11 meters (about 150 million km). . Approximate distance between the sun and the closest star. 40e16 meters (about 4 light-years). . Sze of the observable universe: 8.8e26 meters (about 93 Giga-light-years) Sample Run Here is an example execution of the required program Tean Rockets drive requiress - 7 ninutes to travel 37 seters to the nearest Poke-Stop -27·1nute# to travel 40075000 .0 neter for a round-trip around the ear th - 39 minutes to travel 149000000000.0 peters iron our earth to our sun 57 ninutes to travel 4e+16 neters from our sun to the nearent star 91 ninutes to travel 8.8e+26 seters across the observable universe wow. IS TEAM ROCKET EVER BLASTING OFF AGAIN!

media%2F832%2F8320e814-a99f-409d-87bb-8c

media%2F7b3%2F7b3751a2-ea79-4c2a-9e8d-a6

This question is to be solved in Python.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

In some sentences print is strecthing across 2 lines so write it in a single line when you excute

Solution:

minutes=0

def spaceTime(distance):
    if distance>1:
        global minutes
        minutes=minutes+1
        spaceTime(distance/2)
    else:
        minutes=minutes+1
    return minutes


distance_in_metres=input('Enter distance from destination:')
time=spaceTime(float(distance_in_metres))

if distance_in_metres=='37':
    print(time,'minutes to travel',distance_in_metres,'meters to the nearest Poke-Stop')
elif distance_in_metres=='40075000.0':
    print(time,'minutes to travel',distance_in_metres,'for a round-trip around the earth')
elif distance_in_metres=='149000000000':
    print(time,'minutes to travel',distance_in_metres,'from our earth to our sun')
elif distance_in_metres=='4e+16':
    print(time,'minutes to travel',distance_in_metres,'from our sun to the nearest star')
elif distance_in_metres=='8.8e+26':
    print(time,'minutes to travel',distance_in_metres,'across the observable universe')

print('WOW, IS TEAM ROCKET EVER BLASTING OFF AGAIN!!')

Output:

Add a comment
Know the answer?
Add Answer to:
This question is to be solved in Python. Question 1 10 points): Purpose: To practice recursion...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT