For the exercise The Nile (https://www.codecademy.com/courses/learn-python-3/projects/function-args-the-nile), I’m trying to figure out how to test the function calculate_driver_cost by calling it with my own arguments.
The function is defined as:
def calculate_driver_cost(distance, *drivers): cheapest_driver = None cheapest_driver_price = None for driver in drivers: driver_time = driver.speed * distance price_for_driver = driver.salary * driver_time if cheapest_driver is None: cheapest_driver = driver cheapest_driver_price = price_for_driver elif price_for_driver < cheapest_driver_price: cheapest_driver = driver cheapest_driver_price = price_for_driver return cheapest_driver_price, cheapest_driver
To call the function, I first created a Driver class and then created 2 drivers (not sure if I’m doing the right thing)
class Driver: def __init__(self, speed, salary): self.speed = speed self.salary = salary driver1 = Driver(100 ,5) driver2 = Driver(50, 100) print(calculate_driver_cost(8, driver1, driver2))
This is what is returned: (4000, <main.Driver object at 0x7fbfcd086c88>)
How do I return the cheapest driver instead of the location code thing?? And is this even the way to go about calling the function.
Thanks in advance,