Question: [1] Objectives: This assignment will allow you to practice the two loops structures: for-loop and while-loop. As a requirement, you must use both of these
![[1] Objectives: This assignment will allow you to practice the two](https://dsd5zvtm8ll6.cloudfront.net/si.experts.images/questions/2024/09/66f3151eea3fb_68666f3151e62dc8.jpg)
[1] Objectives: This assignment will allow you to practice the two loops structures: for-loop and while-loop. As a requirement, you must use both of these loops in the assignment and use a nested loop. We are also using a random number generator from the library. You may print the numbers using its default format (ugly, maybe). If you want to make the output look better than that, you can start using f-string. I will show some examples of f-strings during the demo. Formatting the output string is NOT a requirement since it will be taught later. [2] Description: (The Snail in the Well Simulator) The goal for this assignment is to write a program simulating a snail climbing up the well. For every minute, the snail would climb up 2, 3, 4 or 5 cm. However, it would then slip down 1, 2, or 3 cm within the same minute. We know that the snail starts at location 0 and is x cm away from the top of the well. Step 1: Get the necessary parameters. See sample output. Step 2: Write a while-loop to let the snail go up and down. The loop should terminate when the snail is solidly on top of the well. Inside the loop, print the detail of the simulation so we can track the simulation. It is possible that the snail climbs up 1 cm and slides down 2 cm in the same minute. That is why the location of the snail can be a negative number. You should test this part completely before moving to the next step. Step 3: Wrap a for-loop around the while-loop to repeatedly simulate the process multiple times. In order to repeat the simulation, you have to reset some variables to their original value. At the same time, you want to collect some statistics for later use. . Step 4: At the end of the program, print the average time for a snail to reach the top. Hint: use random.choice) for randomly selecting the climb up and slip-down distances. [3] Output: A sample output is given below. Enter the Distance to the Top 10 Enter Number of Trials . Travel time for Trial is 6 minutes 25-35 Travel time for Trial 2 is 7 minutes. Travel time for Trial 3 is 6 minutes The average travel time for 100 trails is
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
