Sal's Shipping name error

this is the error:

File “script.py”, line 50
% (cost, method)
^
IndentationError: unexpected indent

Post the entire function in a reply, please. It appears you have left off the format method and its arguments to fill the placeholders. And do check that the indentation of the entire function is in unison.

https://gist.github.com/0643b362eaa185036330a74791abb021

you can see all my code in the link

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

That’s line 49 and 50. It should all be on line 49. Remember to include the .format() method.

where do i apply the .format()? at line 49?

return “The cheapest option available is $%.2f with %s shipping.” .format() % (cost, method)

can you help me solve the puzzle its missing please i dont seem to find the solution

You’re almost there. It was my bad to say include format(). The % is the method. Take it out, again, and just be sure everything is on one line.

return "... " % (cost, method)

... means all the stuff you have between the quotes.

i’ve done it but now there are new errors lol

Traceback (most recent call last):
File “script.py”, line 51, in
print(cheapest_shipping_method(4.8))
File “script.py”, line 35, in cheapest_shipping_method
ground = shipping_cost_ground(weight)
NameError: name ‘shipping_cost_ground’ is not defined

can you help me with this new errors please

https://gist.github.com/4e8dfc3096fba3f209a00c528174eb16

Okay. I’ll run your latest iteration and see what errors come up. We’re looking at another NameError so the problem is the same, just with a different name. Search all the function signatures and look for the method. Is there a difference?

first error i dont understand it as line 51 is a method that has a function in line 33

>>> 
= RESTART: C:/Users/../users/sals_shipping_thomas_richards.py
53.6
6.0
Traceback (most recent call last):
  File "C:/Users/../users/sals_shipping_thomas_richards.py", line 51, in <module>
    print(cheapest_shipping_method(4.8))
  File "C:/Users/../users/sals_shipping_thomas_richards.py", line 35, in cheapest_shipping_method
    ground = shipping_cost_ground(weight)
NameError: name 'shipping_cost_ground' is not defined
>>> dir()
[..., 'cheapest_shipping_method', 'ground_shipping', 'shipping_cost_drone', 'shipping_cost_premium']
>>> 

Line 51 is a call to the function at line 33. It’s when we invoke the function with an argument and await the response.

Promise me you will go back to the Python 2 course and start at the beginning. If you are a Pro subscriber, then include the Python 3 beginner course. Those courses are crucial and should be fully completed before taking on any projects. We only learn from projects if we already have the basic tools in our toolkit. This is not the place to be learning rudiments. Just saying…

i still dont know what to change for the errors not to appear

We’re looking right at it, in the shell output, above.

Compare the two ground shipping names.

The fix will be locate the ground_shipping signature (line 1) and replace the name with shipping_cost_ground. That will resolve the name error.

oh god, finally I managed to solve it.

I am a pro member and I am taking the career path “Computer science” however, I am very much a beginner, and it’s teaching my Python syntax, Python control flow, etc. but it doesn’t say if it’s python 2 or 3 like you mentioned. would you suggest me to keep with this career path and that’s not the right thing for beginners?

1 Like

One strongly suggests putting that path on hold and take the Learn Python 3 track to its completion. The intro units in the CS path are really only for review, not for new consumption. Go consume the Learn tracks, first. After that we will be having a different conversation.

I can’t say as there is much to be gained by taking the free, Learn Python 2 track, but it will be a look back in time to the earlier syntax. One really doesn’t think it matters, at this point. Python 3 is fully the supported version. Python 2 is effectively a dead language. Would it be fun to learn? About as much fun as learning Latin, one supposes.


Errata

There are some course modules in the CS path that are Python 2 based, and hopefully CC will get them updated soon. It may be necessary on those occasions to get a backgrounder on the older code, but that doesn’t suggest we need to learn Python 2, first. Hardly. Stick to 3 and above (did I hear 4 coming around the corner?)

Ok so i have take the Learn tracks before. I will learn Python 3 first then.
I am pretty much trying to learn python or Java because i am planning on doing masters on Software engineering and as i am new to coding, I just thought of learning Python a bit before hand.

Is there any other suggestion you think I should learn aside from Python 3?

Right now, I wouldn’t suggest any distractions. Pour yourself into Python 3 rudiments and spend several weeks deployed in that endeavor. Don’t race through it. Master the basics. That means algorithms, syntax, usage, variations, error detecting, trapping and handling, data types, classes, modules, and so on. There is a lot to take in and if you have the time, spend it all on this one language, not for what it affords that is different from the others, but what it affords that is similar to all others. Once you grasp the programming concepts that this language makes easy to learn, you will not be grappling with them in Java or C.

You may be a very fast l;earner but I would still put February as when to start the CS track, after you’ve consumed all the Python learning and project modules. Be prepared to refresh all your math skills, too. Statistics and probability; linear algebra; polynomials; set theory; and so on. You’ll need them.

Be prepared to move into the Command Line, at this point, as a lot happens there in terms of getting your local environment set up. Leave this till Feb. Once you get into the CS path you’ll be using SQL, Python libraries, &c. It will be a jump in pace, which is why I stress taking the next couple months to focus on one thing. Python 3, and everything you can learn about it. Be a documentation guru by then.

3 Likes