What wrong in the code? why dose it not find the function

can somebody please explain to me why my code (the last functions) dose not work?

Your cheapest_shipping function is indented under the drone_shipping function. This prevents it from being called outside of the drone_shipping function. You’d want to make sure its not indented at all.

Other things I’d like to point out:

  • What’s the point of the flat_charge variable inside the drone_shipping method? Unless you change its value or add some other functionality to the function, the variable is unnecessary.
  • You have a typo on line 31 (primium rather than premium).

thank you man…
the code is now working but there is still something i dont understand why its happen…
i put a code in the function that say that the result should print the value of premium_ground_shipment
(witch is 125) and also the title “premium shipment” but the results of the code show me just the title and a diffrent value number… you got any idea why?

Take a look at your indentation on line 40. I believe you meant to put cost = ground inside the else block but didn’t indent it properly. Python is a language that relies on indentation to group statements and to indicate which lines of code should be run, and when.

By neglecting to indent cost = ground, you’ve effectively set cost to the value of ground every time your cheapest_shipping method runs, meaning it will always print the value of ground rather than the cost of the cheapest shipping method.

I think one thing throwing you off might be how you write your else statements. You should format your else statements as shown below. You can find more on if-elif-else statements here.

if num > 5:
  print(str(num) + " is greater than 5.")
  print(str(num) + " is not greater than 5.")

i dont understand… so how i should have wrote it?

I explained it in the above post. Look at the code I provided as an example and take a look at the link as well. Your else statements should not be on one line, rather, they should look similar to your if statements, but without a condition.

The main issue, however, is that your line cost = ground is unindented, meaning it’s at the function level rather than being inside the else block. This means the line executes every time rather than only when ground shipping is the cheapest shipping method. This causes your function to return the cost for ground shipping every time it is called.


Hi question about the code …
I noticed that in lines 36 37 if I do a inversion of the values ​​and put the cost value before the method value the result of the function creates a mistake answer … can someone please explain to me why …?

This is to do with the indentation of the code: see how the method variable is the indented along with the else? This means that it will be executed after the if…elif…else code-no matter which of the if blocks run. Therefore, if you reverse this, the cost variable will always be assigned to ground.

1 Like