Please answer in python Write a method called add_racer which takes in a Boat object and adds it to the end of the racers list. The function does not return anything. Write a method called print_racers which loops through racers and prints the Boat objects. This function takes in no parameters (other than self) and returns nothing. Write a method called count that returns the number of racers. Write a method called race.  The race function calls the move function for all of the racers in the BoatRace.  Once all the racers have moved, call the print_racers method to display information about the progress of each boat. Then, check if any of the racer’s current_progress is greater than or equal to the race’s distance.  If so, then return a list of all of the racers whose current_progress is greater than or equal to distance.  If no racer has finished the race then repeat the calls to move and check until at least one racer has finished the race. Examples: Copy the following if __name__ == "__main__" block into your hw11.py file, and comment out tests for parts of the class you haven’t implemented yet.  The lines that have output include the expected value next to them as a comment (note that some lines are random and your output will not match exactly).

Programming Logic & Design Comprehensive
9th Edition
ISBN:9781337669405
Author:FARRELL
Publisher:FARRELL
Chapter9: Advanced Modularization Techniques
Section: Chapter Questions
Problem 1GZ
icon
Related questions
Question

Please answer in python

  • Write a method called add_racer which takes in a Boat object and adds it to the end of the racers list. The function does not return anything.
  • Write a method called print_racers which loops through racers and prints the Boat objects. This function takes in no parameters (other than self) and returns nothing.
  • Write a method called count that returns the number of racers.
  • Write a method called race. 
    • The race function calls the move function for all of the racers in the BoatRace. 
    • Once all the racers have moved, call the print_racers method to display information about the progress of each boat.
    • Then, check if any of the racer’s current_progress is greater than or equal to the race’s distance. 
    • If so, then return a list of all of the racers whose current_progress is greater than or equal to distance. 
    • If no racer has finished the race then repeat the calls to move and check until at least one racer has finished the race.

Examples:

Copy the following if __name__ == "__main__" block into your hw11.py file, and comment out tests for parts of the class you haven’t implemented yet.  The lines that have output include the expected value next to them as a comment (note that some lines are random and your output will not match exactly).

 

The first race example in the code below should finish within a few turns, and unless you get extremely unlucky, The Leaf should win a solo victory almost every time due to its top speed.  The second race, on the other hand, should almost always finish in a single round with three or four boats tied for victory.

if __name__ == '__main__':

    the_race = BoatRace('the_big_one.csv')

    the_race.add_racer(Boat("Late", 2))

    the_race.print_racers() #The Fire Ball: 0

                            #The Leaf: 0

                            #Late: 0

    print(the_race.count()) #3

    result = the_race.race() #The Fire Ball: 5

                             #The Leaf: 39

                             #Late: 2

                             #The Fire Ball: 17

                             #The Leaf: 56

                             #Late: 4

                             #The Fire Ball: 19

                             #The Leaf: 145

                             #Late: 4

    print(result) #[<__main__.Boat object at 0x03A2E4F0>]

    print(result[0].get_boat_name()) #The Leaf

    print(result[0].get_current_progress()) #145

 

    second_race = BoatRace('very_short.csv')

    second_result = second_race.race() #Runner: 84

                                       #Whirlwind: 10

                                       #Boaty McBoatFace: 4

                                       #Greased Lightning: 78

                                       #Much Speed: 43

    print(len(second_result)) #4

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Passing Array as Argument
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage