Question: [ Task 1 ] - The Runners Are Here ( 2 0 % ) You are NOT allowed to use try / except blocks in
Task The Runners Are Here
You are NOT allowed to use tryexcept blocks in Task
Task Setup
In this part, you are given a class called Runner that contains a few instance variables and some class variables. The purpose of each of them is defined below:
maxenergy int : The maximum energy of the runner ie same for all runners
name str: The name of a runner.
age int: The age of the runner.
country str: The country of the runner.
energy int: The current level of energy for the player. It starts at max energy.
sprintspeed float: The speed at which the runner runs when participating in a short race in meters per second
endurancespeed float : The speed at which the runner runs when participating in a marathon in meters per second
What has been given with errors
The class also contains the following methods:
initself name, age, country, sprintspeed, endurancespeed: this method creates the runner with the attributes passed to the method. There are certain limitations to the attribute values:
name must be an alphanumeric string can contain spaces
age must be an integer between and both inclusive
country must be a string and its value must be from the ones contained in the 'name' column of the csv countries.csv provided in the directory this file is currently being run.
NOTE : You may assume that countries.csv always exists
sprintspeed must be a float and its value should lie between and in meters per second both inclusive
endurancespeed must be a float and its value should lie between and in meters per second both inclusive
drainenergyself drainpoints: this method gets an integer and drains the energy of the runner by the value of drainpoints passed.
The value of drain points cannot be less than or more than the maxenergy value of the runner.
Also, the leftover energy of the player once the energy is drained cannot be less than After this method concludes, the energy of the player should have been reduced by the value passed in the function.
recoverenergyself recoveryamount: this method gets an integer and recovers the energy of the player by the value of recoveryamount passed. The value of the energy of the player cannot exceed the maximum energy. If the energy of the player after adding recoveryamount goes over the maxenergy then you should set the energy to the maxenergy. You should also note that recoveryamount should not be more than maxenergy.
runraceself racetype, distance float : this method takes in the race type either "short" or "long" and distance; A positive floating value; in kilometers of the race and is a float value. It then returns the floating value of the time taken in seconds; rounded to decimal places to complete the race. After this method concludes, there should be no change in the stats of the player. Please note that if the race is a short race, use the sprint speed of the runner. If the race is a marathon, then use the endurance speed of the runner.
strself : this method just returns the details of the runner. You don't need to test this method.
Remember! You may need to validate the input that these methods receive and raise relevant errors. You will also need to assert the post conditions of these methods, that are mentioned above.
For You To Do
Most of the code has already been done for you. However, your TAs have become lazy and made code mistakes. :
You are tasked with the following:
Fix the errors made in the class, variables, and methods based on the descriptions mentioned above.
Check the preconditions and postconditions for each of the methods. Make sure to raise the relevant errors if incorrect values are passed to the functions.
Document your code including typehinting for all variables, arguments for functions and methods, and relevant docstrings for each method and class.
Build on the unit tests that have already been given to you in the file testrunner.py You are expected to create at least three tests for each method. You should create these additional tests in a separate testing function in the given class.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
