Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Choose some type of object that would make sense to compete in a race (ie. boxcar, horse, person, ships, bikes, greyhounds, snails... be creative). Formulate

Choose some type of object that would make sense to compete in a race (ie. boxcar, horse, person, ships, bikes, greyhounds, snails... be creative). Formulate a class of this type of object. It will have a fixed speed it can run (or drive) and maximum distance it can go before becoming exhausted (or running out of gas). It should also have a name to identify it by, but keep it simple (ie. 'Horse 0', 'Horse 1', etc.). During the initialization, the speed and maximum distance should be determined by a random value within a range that makes sense for that type of object, but with no units (ie. assuming miles you would use 40-44 for horse speedLinks to an external site. and 2 for distance of a horse raceLinks to an external site.). Use random.uniform(val1,val2) if you want to generate a random decimal value rather than an integer, particularly useful with small numbers.

Formulate a race that is initialized with a distance that is specified when it is created (ie. pass as a parameter to the __init__). The number of racers can be determined when a new race is started using a start_race method. You'll also need a method to determine which racer wins (based on highest speed within the given distance). Be sure to consider what happens if no one wins!

In your main function, Formulate a race with a distance of your choice, print the race distance, and start the race with 5 racers, and print out the details of each racer (name, speed, max distance), and then determine which one wins and print the result of the race. Using the same race (don't form a new one), start the race with 8 racers and again print out the details of each racer and then print out which one wins.

Here is a possible output from a Horse race (note that the results of the races will be different each time you run it):

Race Distance: 2
Horse 0 Speed: 40 Max Distance: 1.886602776175576
Horse 1 Speed: 43 Max Distance: 2.2543107494109664
Horse 2 Speed: 40 Max Distance: 2.3422628628436923
Horse 3 Speed: 41 Max Distance: 2.237815470871785
Horse 4 Speed: 40 Max Distance: 1.7883226018197373
Winner: Horse 1
Horse 0 Speed: 43 Max Distance: 1.7835187365203125
Horse 1 Speed: 43 Max Distance: 1.651116450587179
Horse 2 Speed: 43 Max Distance: 1.64315256424609
Horse 3 Speed: 42 Max Distance: 2.1279316714432746
Horse 4 Speed: 43 Max Distance: 1.5312846230783852
Horse 5 Speed: 41 Max Distance: 2.44574965247417
Horse 6 Speed: 42 Max Distance: 1.688510862362611
Horse 7 Speed: 43 Max Distance: 1.825278099402782
Winner: Horse 3


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

Global Marketing management

Authors: Masaaki Kotabe, Kristiaan Helsen

5th edition

470505745, 978-0470505748

More Books

Students also viewed these Programming questions