0

I'm new to python, so this might be super easy, however, I want to the user to write the weight of the package. Package 1, we can call it. Then the user can write the weight for another package, etc. In the end, the code adds the prices together, and it writes out the total price.

This is the code I have. It only does it for 1 package. Not sure how to more than 1 package.

def package_price(kg):
    if kg < 0:
        return "The number is negative "
    if kg <= 10:
        return "That would be 149kr"
    elif kg <= 25:
        return "That would be 268kr"
    elif kg <= 35:
        return "That would be 381kr"
    else:
        return "The package is too heavy"


weight = input("How much does the package weight?: ")
kg = int(weight)
package = package_price(kg)
print(package)
8
  • 1
    Are you sure you want to multiply weights rather than add them? Commented Jan 16, 2020 at 16:24
  • Simply write another input statement, like you did for weight and add the result to the first input. Commented Jan 16, 2020 at 16:25
  • oh yeah, meant that. I'll edit it in the text. Commented Jan 16, 2020 at 16:25
  • What is the relevance of package_price in the context of your question? Commented Jan 16, 2020 at 16:27
  • @Austin I want the user to have more than 1 package. So 1 package under 25kg would be 268kr, and then they might have another package that weights 8kg. Then the code would need to add the prices together. Commented Jan 16, 2020 at 16:32

1 Answer 1

1

You need two input statements, then add the results together.

weight1 = int(input("How much does the first package weight?: "))
price1 = package_price(weight1)

weight2 = int(input("How much does the second package weight?: "))
price2 = package_price(weight2)

print(price1 + price2)
Sign up to request clarification or add additional context in comments.

5 Comments

I set the limit to 35kg, so the code combines them into 1 big package, and then it goes over 35kg.
Is that the behavior you want? If not, what do you want it to do?
I want it to the user to write in the weight of the package. Then they write in another weight for another package. Then it finds out how much the first package costs, and how much the second one costs. Then it combines the prices.
Fixed my answer.
Thanks for the help!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.