I Need Help with a Project

I’m on question 8 which asks you to test your code. My code did not pass the test, still trying to figure out why.


“calculate_shipping_cost() did not format the result in a string”

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

In order for anyone to help, you’ll have to post your code. Don’t forget to click </> first, and then paste your code in the space indicated.

You have to return your value from your function.

But a return is already present in the funcion “format_price”

The return in format_price() returns the value to the calling statement, which in this case is inside your function. Your function, calculate_shipping_cost(), must, in turn, return the received value.

def area_format(rad, area):
    return "the area of your circle of radius {} is {}".format(rad, area)

def area_circle(rad):
    area = 3.14 * rad**2
    return area_format(rad, area)



the area of your circle of radius 3 is 28.26
1 Like

When I do:

return format_price(price)

I get “Inconsistent use of tabs and spaces”

That’s a bug, or at least over-sensitivity in the editor. Un-indent the line all the way to the left, then re-indent it using spacebar only (probably 2 spaces). If that doesn’t work, re-indent using tab.

Now I’m getting this “UnicodeEncodeError: ‘ascii’ codec can’t encode character ‘\u2705’ in position 0: ordinal not in range(128)”

Ah! A bug!
Go to test.py and scroll down. You’ll see a number of green check marks. Replace each with “OK!” or anything you like, then click “Save”, then go back to your script and try again.


That’s insane, how’d you figure that one out?

When I took the course, I got the same error, which essentially says that it’s trying to print a character that it can’t print. So I looked for what was supposed to be printed in test.py, and those check marks jumped out!
I just reported it again.