Example #1
0
def calculate_shipping_cost(from_coords, to_coords, shipping_type='Overnight'):
    from_lat, from_long = from_coords
    to_lat, to_long = to_coords
    distance = get_distance(from_lat, from_long, to_lat, to_long)
    shipping_rate = SHIPPING_PRICES[shipping_type]
    price = distance * shipping_rate
    return format_price(price)
Example #2
0
def calculate_shipping_cost(from_coords, to_coords, shipping_type = 'Overnight'):
  # from_lat, from_long = from_coords
  # to_lat, to_long = to_coords
  distance = get_distance(*from_coords, *to_coords)
  shipping_rate = SHIPPING_PRICES[shipping_type]
  price = shipping_rate * distance
  return format_price(price)
Example #3
0
def calculate_shipping_cost(from_coords, to_coords, shipping_type = 'Overnight'): # note shipping_type has been set to Overnight by defauly, becuase some customers forget to click this. It is key information so we need to put something in here.  
  #from_lat, from_long = from_coords # unpacking 
  #to_lat, to_long = to_coords # unpacking 
  distance = get_distance(*from_coords, *to_coords) #This is the same as doing this: distance = get_distance(from_lat, from_long, to_lat, to_long), just in a more compact way. Also, we don't need to unpack them in the previous two lines. 
  shipping_rate = SHIPPING_PRICES[shipping_type]
  price = distance * shipping_rate
  return format_price(price)
def calculate_shipping_cost(from_coords, to_coords, shipping_type='Overnight'):
    from_lat = from_coords[0]
    to_lat = to_coords[0]
    from_long = from_coords[1]
    to_long = to_coords[1]
    shipping_rate = SHIPPING_PRICES.get(shipping_type)
    distance = get_distance(from_lat, from_long, to_lat, to_long)
    shipping_price = shipping_rate * distance
    return format_price(shipping_price)
def calculate_shipping_cost(from_coords, to_coords, shipping_type="Overnight"):
    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.get(shipping_type)
    #shipping_rate = SHIPPING_PRICES[shipping_type]
    price = distance * shipping_rate
    return format_price(price)
def calculate_shipping_cost(from_coords, to_coords, shipping_type="Overnight"):
    # Get the distance between the two coords points.
    distance = get_distance(*from_coords, *to_coords)
    # Getting the shipping rate related to the shipping type
    shipping_rate = SHIPPING_PRICES[shipping_type]
    # Calculate the price
    price = distance * shipping_rate
    # Return the formated price
    return format_price(price)
def calculate_shipping_cost(from_coords, to_coords, shipping_type='Overnight'):
    (from_lat, from_long) = from_coords
    (to_lat, to_long) = to_coords

    distance = get_distance(*from_coords, *to_coords)
    shipping_rate = SHIPPING_PRICES[shipping_type]
    price = distance * shipping_rate
    formatted_price = format_price(price)
    return formatted_price
def calculate_shipping_cost(from_coords, to_coords, shipping_type='Overnight'):
    from_lat, from_long = from_coords
    to_lat, to_long = to_coords
    distance = get_distance(from_lat, from_long, to_lat, to_long)
    price = 0
    for shipping_type_key, shipping_rate_value in SHIPPING_PRICES.items():
        if shipping_type_key == shipping_type:
            price = distance * shipping_rate_value
    return format_price(price)
Example #9
0
def calculate_shipping_cost(from_coords, to_coords, shipping_type='Overnight'):
    from_lat, from_lon = from_coords
    to_lat, to_lon = to_coords

    distance = get_distance(from_lat, from_lon, to_lat, to_lon)

    rate = SHIPPING_PRICES.get(shipping_type)

    price = distance * rate
    return format_price(price)
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)
Example #11
0
def calculate_shipping_cost(from_coords, to_coords, shipping_type='Overnight'):
    # print(from_coords) # (0, 1)
    # print(to_coords) # (2, 3)
    # print(shipping_type) #Defaults to Overnight.

    #Method 1:
    # from_lat, from_long = from_coords #Saves as 0, 1.
    # to_lat, to_long = to_coords #Saves as 2, 3.
    # distance = get_distance(from_lat, from_long, to_lat, to_long)

    #Method 2
    distance = get_distance(*from_coords, *to_coords)
    print(distance)  # 0.5774278040487338

    shipping_rate = SHIPPING_PRICES[shipping_type]
    print(shipping_rate)  # 2.3

    price = distance * shipping_rate
    print(price)  # 1.3280839493120877
    print(format_price(price))  # $1.33

    return format_price(price)
def calculate_shipping_cost(from_coords, to_coords, shipping_type='Overnight'):
    # unpack those tuples into from_lat, from_long, to_lat, and to_long
    from_lat, from_long = from_coords
    to_lat, to_long = to_coords

    # get_distance()function looks for all four as separate arguments, we’ll need to separate these variables out.
    distance = get_distance(*from_coords, *to_coords)

    # get the shipping_rate by using the provided SHIPPING_PRICES dictionary
    shipping_rate = SHIPPING_PRICES[shipping_type]

    # price by multiplying the distance by the shipping_rate
    price = distance * shipping_rate
    return format_price(price)
Example #13
0
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.
    # Inside calculate_shipping_cost unpack those tuples into from_lat, from_long, to_lat, and to_long.
    from_lat, from_long = from_coords
    to_lat, to_long = to_coords
    # Now call get_distance(from_lat, from_long, to_lat, to_long) and save the result as distance.
    distance = get_distance(from_lat, from_long, to_lat, to_long)
    # There’s other ways to separate those two coordinates when calling this function, how would you have done it?
    # distance = get_distance(*from_coords, *to_coords)
    # Next, get the shipping_rate by using the provided SHIPPING_PRICES dictionary and fetching the key passed in as shipping_type.
    shipping_rate = SHIPPING_PRICES[shipping_type]
    # Calculate the price by multiplying the distance by the shipping_rate.
    price = distance * shipping_rate
    # Finally, return the formatted price, created by calling the provided format_price() on the price itself.
    return format_price(price)
Example #14
0
def calculate_shipping_cost(from_coords, to_coords, shipping_type="Overnight"):
    # we gave shipping_type a default argument in case shoppers don't indicate shipping_type

    # both coordinates are given as tuples containing the latitude and the longitude
    # since our get_distance() function looks for all four as separate arguments, we’ll need to separate these variables out using variable unpacking
    from_lat, from_long = from_coords
    to_lat, to_long = to_coords
    # now we can get the distance
    distance = get_distance(from_lat, from_long, to_lat, to_long)
    # also could have used:
    # get_distance(*from_coords, *to_coords)

    # we get the shipping_rate by finding shipping_type in the given SHIPPING_PRICES dictionary
    shipping_rate = SHIPPING_PRICES[shipping_type]

    # calculate the price
    price = distance * shipping_rate

    # return the formatted price
    return format_price(price)
Example #15
0
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)
Example #16
0
  from_long = from_coords[1]
  to_lat = to_coords[0]
  to_long = to_coords[1]
  #print ("from_lat = " + str(from_lat))
  #print ("from_long = " + str(from_long))
  #print ("to_lat = " + str(to_lat))
  #print ("to_long = " + str(to_long))
  
  distance = get_distance(from_lat, from_long, to_lat, to_long)
  #distance = get_distance(*from_coords, *to_coords) #also works (unpacking)
  
  shipping_rate = SHIPPING_PRICES.get(shipping_type)
  
  price = distance * shipping_rate
  
  return format_price(price)
  

# Test the function by calling 
test_function(calculate_shipping_cost)

# 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