-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path11_FunctionArguments_TheNile.py
More file actions
53 lines (46 loc) · 2.03 KB
/
Copy path11_FunctionArguments_TheNile.py
File metadata and controls
53 lines (46 loc) · 2.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
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"):
#Both from_coords and to_coords are tuples, containing first the latitude and then the longitude.
# Since our get_distance() function looks for all four as separate arguments,
# we’ll need to separate these variables out.
#
#from_lat,from_long=from_coords
#to_lat,to_long=to_coords
#distance=get_distance(from_lat, from_long, to_lat, to_long)
distance=get_distance(*from_coords,*to_coords)
shipping_rate =SHIPPING_PRICES[shipping_type]
price=shipping_rate*distance
return format_price(price)
# Test the function by calling
test_function(calculate_shipping_cost)
# Define calculate_driver_cost() here
#In order to find the best person, we need to calculate how much it would cost
# for any of the drivers to fulfill this order.
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==None or price_for_driver< cheapest_driver_price:
cheapest_driver=driver
cheapest_driver_price=price_for_driver
#elif price_for_driver< cheapest_driver_price:
#cheapest_drive=driver
#cheapest_driver_price=price_for_driver
return cheapest_driver_price, cheapest_driver
# Test the function by calling
test_function(calculate_driver_cost)
# Define calculate_money_made() here
#This function will be passed a number of Trip IDs with corresponding trip information as arguments,
# so let’s just take any keyword arguments passed into it. Store them all as trips
def calculate_money_made(**trips):
total_money_made =0
for trip_id,trip in trips.items():
trip_revenue = trip.cost - trip.driver.cost
total_money_made += trip_revenue
return total_money_made
# Test the function by calling
test_function(calculate_money_made)