Sal's Shipping - Float Issue!

Hello! I am currently working on the third project for the introduction to python and am getting the type error ‘‘float’ object is not callable’

I am not sure how to adjust my code. Also, the walkthrough uses strange syntax ‘%.2f’ and ‘% (cost)’ that I don’t understand.

Can someone please explain what is going on?

My Code:
#Ground shipping rates
def ground_rates(weight):
if weight <= 2:
cost = weight * 1.5 + 20
return cost
elif (weight > 2) and (weight <= 6):
cost = weight * 3 + 20
return cost
elif (weight > 6) and (weight <= 10):
cost = weight * 4 + 20
return cost
else:
cost = weight * 4.75 + 20
return cost

#Primium shipping flat rate
primium_ground_shipping = 125.00

#Drone rates
def drone_rates(weight):
if weight <= 2:
cost = weight * 4.50
return cost
elif (weight > 2) and (weight <= 6):
cost = weight * 9.00
return cost
elif (weight > 6) and (weight <= 10):
cost = weight * 12.00
return cost
else:
cost = weight * 14.25
return cost

#Best shipping option determiner

def best_option(weight):
if (primium_ground_shipping() < ground_rates()) and (primium_ground_shipping() < drone_rates()):
cost = 125.00
print(‘Go primium for $’ + str(cost))

elif (ground_rates() < primium_ground_shipping()) and (ground_rates() < drone_rates()):
cost = ground_rates()
print(‘Go ground for $’ + str(cost))

else:
cost = drone_rates()
print(‘Go drone for $’ +str(cost))

best_option(4.8)

Hello @taylorrayne, welcome to the forums! Check this line:

is primium_ground_shipping a variable or a function?

Also, the %s and %.2f is an exmaple of string formatting here is an article on it.


P.S. See this thread on how to correctly format your code in the forums:

1 Like

Hi @codeneutrino! Thank you very much for following up.
In terms of primium_ground_shipping, it is a variable. Could this distinction relate to the TypeError I am getting?

And thank you for providing the link to the string formatting article - although, I could not find anything on how the methods mentioned compare to my use of str(). What might be the difference in how I am using this to convert my integer into a string and actual string formating be?

Also, appreciate the formating resource!

I think it could be the cause of the error.


The way you format strings is string concatenation. It is a way of joining two or more strings together; that’s why you need to use the str() on non-string objects when concatenating. The other methods of string formatting involve inserting variable values into the string. Similar to most other languages. It is mainly for readability that one uses string formatting over concatenation. Here is an article on time/memory usage of concatenation vs other formatting methods.

1 Like

Amazing! Thanks again, @codeneutrino.
It turns out you were correct. Getting clear on what was a variable vs a function has my code is up and running now.
And thanks for another great link!
I appreciate your help :slight_smile:

1 Like