Sal's Shipping - Print Cheapest Method, need help


I reached the last step of the Sal’s shipping exercise, and got stuck so I looked at the help video. Besides that the solution covers something not taught so far (the % variables, which I understand now) I cannot get the code to print the result expected.

I have no error, it just doesn’t produce anything

the last 2 lines here:


I have pasted the code here

Anyone would know why?
Thank you

Hey there @digitalcoder52658!! Welcome to the forums :grinning:

Take a look at your print() on line 49.

    method = "drone"
    cost = drone

      "The cheapest option available is $%.2f with %s shipping" 
      % (cost,method)

Notice it is inside of the else block, which only runs under specific conditions.

Another thing to bring up here, is the use of a return statement.
Though your function may generate a correct answer and print it, it never returns it. So there is no way to store the value.

Consider this function:

def add(n1, n2):
  print(n1 + n2)

add(3, 5)  #prints 8

This is all fine and good if I just want to know the result of adding 3 and 5, but suppose I need to use that value later on in the program. I could use a return:

def add(n1, n2):
  return n1 + n2  

number = add(3, 5) #number equal to 8

Personally I would suggest adding a return to your last function, since it can add a lot more use and flexibility to the program.


Oh, thank you! I should have checked that indentation was correct.

Also about your return tip, it makes total sense you are right! I will definitely take note.