The Nile - Python Intermediate Project

I believe I have the exact same code as laid out in the walkthrough video, however when testing calculate_driver_cost I am getting the error: calculate_driver_cost() doesn’t expect multiple driver arguments

from nile import get_distance, format_price, SHIPPING_PRICES
from test import test_function

# Define calculate_shipping_cost() here:
def calculate_shipping_cost(from_coords, to_coords, shipping_type = 'Overnight'):
  distance = get_distance(*from_coords, *to_coords)
  shipping_rate = SHIPPING_PRICES[shipping_type]
  price = distance * shipping_rate
  return format_price(price)

# Test the function by calling 

# Define calculate_driver_cost() here
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:
      cheapest_driver = driver
      cheapest_driver_price = price_for_driver
  return cheapest_driver_price, cheapest_driver

# Test the function by calling 

# Define calculate_money_made() here

# Test the function by calling 
# test_function(calculate_money_made)

That output is a little bit deceptive since the test catches any type errors with the same message that unfortunately masks the actual TypeError you get which has nothing to do with the number of driver arguments. The actual exception is raised in the following way:
TypeError: '<' not supported between instances of 'int' and 'Driver'

Double check anywhere you’re passing arguments to that operator and you’ll likely find the issue.

1 Like

Got it, changed both comparisons to integers - thank you for not giving me the exact answer and letting me learn. Have a great weekend good person!