((Simulation: The Tortoise and the Hare) In this problem, you’ll re-create one of the truly great moments in history, namely the classic race of the tortoise and the hare. You’ll use random number generation to develop a simulation of this memorable event. Our contenders begin the race at square 1 of 70 squares. Each square represents a possible position along the race course. The finish line is at square 70. The first contender to reach or pass square 70 is rewarded with a pail of fresh carrots and lettuce. The course weaves its way up the side of a slippery mountain, so occasionally the contenders lose ground. Use variables to keep track of the positions of the animals (i.e., position numbers are 1–70). Start each animal at position 1 (i.e., the “starting gate”). If an animal slips left before square 1, move the animal back to square 1. Generate the percentages in Fig. 10.24 by producing a random integer i in the range 1 ≤i ≤10. For the tortoise, perform a “fast plod” when 1 ≤i ≤5, a “slip” when 6 ≤i ≤7 and a “slow plod” when 8 ≤i ≤10. Use a similar technique to move the hare. Begin the race by printing BANG !!!!! AND THEY'RE OFF !!!!! Then, for each tick of the clock (i.e., each repetition of a loop), print a 70-position line show- ing the letter T in the position of the tortoise and the letter H in the position of the hare. Occa- sionally, the contenders will land on the same square. In this case, the tortoise bites the hare, and your script should print OUCH!!! beginning at that position. All print positions other than the T, the H or the OUCH!!! (in case of a tie) should be blank. After each line is printed, test whether either animal has reached or passed square 70. If so, print the winner, and terminate the simulation. If the tortoise wins, print TORTOISE WINS!!! YAY!!! If the hare wins, print Hare wins. Yuck! If both animals win on the same tick of the clock, you may want to favor the turtle (the “underdog”), or you may want to print It's a tie. If neither animal wins, perform the loop again to simulate the next tick of the clock. When you’re ready to run your script, assemble a group of fans to watch the race. You’ll be amazed at how involved your audience gets!
((Simulation: The Tortoise and the Hare) In this problem, you’ll re-create one of the truly great moments in history, namely the classic race of the tortoise and the hare. You’ll use random number generation to develop a simulation of this memorable event.
Our contenders begin the race at square 1 of 70 squares. Each square represents a possible position along the race course. The finish line is at square 70. The first contender to reach or pass square 70 is rewarded with a pail of fresh carrots and lettuce. The course weaves its way up the side of a slippery mountain, so occasionally the contenders lose ground.
Use variables to keep track of the positions of the animals (i.e., position numbers are 1–70). Start each animal at position 1 (i.e., the “starting gate”). If an animal slips left before square 1, move the animal back to square 1.
Generate the percentages in Fig. 10.24 by producing a random integer i in the range 1 ≤i ≤10. For the tortoise, perform a “fast plod” when 1 ≤i ≤5, a “slip” when 6 ≤i ≤7 and a “slow plod” when 8 ≤i ≤10. Use a similar technique to move the hare.
Begin the race by printing
BANG !!!!! AND THEY'RE OFF !!!!!Then, for each tick of the clock (i.e., each repetition of a loop), print a 70-position line show- ing the letter T in the position of the tortoise and the letter H in the position of the hare. Occa- sionally, the contenders will land on the same square. In this case, the tortoise bites the hare, and your script should print OUCH!!! beginning at that position. All print positions other than the T, the H or the OUCH!!! (in case of a tie) should be blank.
After each line is printed, test whether either animal has reached or passed square 70. If so, print the winner, and terminate the simulation. If the tortoise wins, print TORTOISE WINS!!! YAY!!! If the hare wins, print Hare wins. Yuck! If both animals win on the same tick of the clock, you may want to favor the turtle (the “underdog”), or you may want to print It's a tie. If neither animal wins, perform the loop again to simulate the next tick of the clock. When you’re ready to run your script, assemble a group of fans to watch the race. You’ll be amazed at how involved your audience gets!
![Animal
Move type
Percentage of the time
Actual move
Sleep
Big hop
Big slip
Small hop
Small slip
Hare
20%
No move at all
20%
9 squares to the right
12 squares to the left
1 square to the right
2 squares to the left
10%
30%
20%
Fig. 10.24 | Rules for adjusting the position of the tortoise and the hare. (Part 2 of 2.)
Use variables to keep track of the positions of the animals (i.e., position numbers are 1–70).
Start each animal at position 1 (i.e., the "starting gate"). If an animal slips left before square 1,
move the animal back to square 1.
Generate the percentages in Fig. 10.24 by producing a random integer i in the range
1sis10. For the tortoise, perform a "fast plod" when 1 Si$5, a "slip" when 6 Si S7 and a "slow
plod" when 8 Si<10. Use a similar technique to move the hare.
Begin the race by printing
BANG !!!!!
AND THEY'RE OFF !!!!!
Then, for each tick of the clock (i.e., each repetition of a loop), print a 70-position line show-
ing the letter T in the position of the tortoise and the letter H in the position of the hare. Occa-
sionally, the contenders will land on the same square. In this case, the tortoise bites the hare, and
your script should print OUCH!!! beginning at that position. All print positions other than the T,
the H or the OUCH!!! (in case of a tie) should be blank.
After each line is printed, test whether either animal has reached or passed square 70. If so,
print the winner, and terminate the simulation. If the tortoise wins, print TORTOISE WINS!!! YAY!!!
If the hare wins, print Hare wins. Yuck! If both animals win on the same tick of the clock, you may
want to favor the turtle (the "underdog"), or you may want to print It's a tie. If neither animal
wins, perform the loop again to simulate the next tick of the clock. When you're ready to run your
script, assemble a group of fans to watch the race. You'll be amazed at how involved your audience
gets!
Later in the book, we introduce a number of Dynamic HTML capabilities, such as graphics,
images, animation and sound. As you study those features, you might enjoy enhancing your tor-
toise-and-hare contest simulation.](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2Fb5ac08f7-42c3-4170-80a5-c0dc5b612826%2F9a13b118-bb8c-4a92-8000-f33c0586ab07%2F0oyr4_processed.png&w=3840&q=75)
![10.17 (Simulation: The Tortoise and the Hare) In this problem, you'll re-create one of the truly
great moments in history, namely the classic race of the tortoise and the hare. You'll use random
number generation to develop a simulation of this memorable event.
Our contenders begin the race at square 1 of 70 squares. Each square represents a possible
position along the race course. The finish line is at square 70. The first contender to reach or pass
square 70 is rewarded with a pail of fresh carrots and lettuce. The course weaves its way up the side
of a slippery mountain, so occasionally the contenders lose ground.
There's a clock that ticks once per second. With each tick of the clock, your script should
adjust the position of the animals according to the rules in Fig. 10.24.
Animal
Move type
Percentage of the time
Actual move
Fast plod
Slip
Slow plod
Tortoise
3 squares to the right
6 squares to the left
50%
20%
30%
1 square to the right](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2Fb5ac08f7-42c3-4170-80a5-c0dc5b612826%2F9a13b118-bb8c-4a92-8000-f33c0586ab07%2Flowoe4j_processed.png&w=3840&q=75)
![](/static/compass_v2/shared-icons/check-mark.png)
Trending now
This is a popular solution!
Step by step
Solved in 2 steps
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![C How to Program (8th Edition)](https://www.bartleby.com/isbn_cover_images/9780133976892/9780133976892_smallCoverImage.gif)
![Database Systems: Design, Implementation, & Manag…](https://www.bartleby.com/isbn_cover_images/9781337627900/9781337627900_smallCoverImage.gif)
![Programmable Logic Controllers](https://www.bartleby.com/isbn_cover_images/9780073373843/9780073373843_smallCoverImage.gif)