Https://www.codecademy.com/courses/learn-python-3/projects/python-sals-shipping

https://www.codecademy.com/courses/learn-python-3/projects/python-sals-shipping

Hello,

I am stuck on this part of the code, because whenever I place “<” or “>” the code comes out as read, which it should be white instead. Here is what I have so far:

def shipping_cost_ground(weight):

if weight = 2:

price_per_pound = 1.5

elif weight <= 6

price_per_pound = 3.00

elif weight <= 10

price_per_pound = 4.00

else:

price_per_pound = 4.75

return 20 + (price_per_pound) * weight

print(shipping_cost_ground(8.4))

If I am doing something wrong during this, please let me know.

1 Like

Be sure to use comparison, not assignment. ==

1 Like

I tried doing this:

def shipping_cost_ground(weight):

if weight == 2:

price_per_pound == 1.5

elif weight == 6

price_per_pound = 3.00

elif weight == 10

price_per_pound = 4.00

else:

price_per_pound = 4.75

return 20 + (price_per_pound) * weight

print(shipping_cost_ground(8.4))

I’m still not sure what I am doing wrong

What about in between weight? Note in the specifications it reads 2 lbs or less, and so on with the other weights.

I’m sorry, Im not sure how to write it out. I may have to skip this chapter, since I am trying to fix <= symbol which this symbol “<” comes out red for me.

a > b   #  a is greater than b

The above expression is an assertion that states “A is greater than B”. The expression has a truth value that can go either way… It is, or it isn’t. The expression by itself yields a boolean. This is to say the expression evaluates to a boolean (True or False).

When used in an if statement, its truth value is assessed in order to determine whether to follow the truthy branch, or not.

if a > b:
  # truthy branch

Above is an example of single-way branch, since there is no alternate branch to follow. This is the simplest multi-way branch:

if a > b:
  # truthy branch
else:
  # falsy branch (default)

Above we have described one of the many relationships that we can test our data points against. Think, “How does A relate to B?”

The tyipcal relationship operators we use in Python are,

==
!=
<
>
<=
>=

Notice that if there is an = it is always on the right side of the pairing.

When measuring a value as being some amount or less, we look for the relationship that is less than or equal to.

a <= 2

We wouldn’t expect a weight of zero or less since we’ve just put a package on the scale. This means a can be expected to be a number greater than zero (moot) anywhere up to and including 2 weight measure units (lb, kg, &c.).

Given there is a scale of weight ranges, it is very likely we will implement a multi-way branch that employs elif which allows new conditions.

if a > b:
  # truthy branch
elif a > c:
  # truthy branch
elif a > d:
  # truthy branch
else:
 # default branch

Imagine things as being placed on the scale: If it is NOT less than or equal to 2 then it MUST be greater than 2.

If you mean the syntax highlighting, focus less on the colors and more on whether the code is correct.