简体   繁体   English

如何在 if 语句中使用多个输入

[英]how to use multiple inputs with if statements

I'm new to python, so this might be super easy, however, I want to the user to write the weight of the package.我是 python 新手,所以这可能非常简单,但是,我想让用户写下包裹的重量。 Package 1, we can call it.套餐1,我们可以称之为。 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.它仅适用于 1 个包裹。 Not sure how to more than 1 package.不知道如何超过 1 个包裹。

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)

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)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM