简体   繁体   English

如何多次调用此函数?

[英]How do I call this function multiple times?

#calculates total price of your items as your shopping

print("The sales tax in Lucas County is 7.25%")
sales_tax = 0.0725
price_total=0

price = float(input("Insert price of item "))
price_tax= price * sales_tax
price_semitotal = price_tax + price
print("Price of that item with tax: ", price_semitotal)
price_total+=price_semitotal
print("Total Price: ", price_total)

How do I change this so that it loops and keeps prompting the user to add more items?如何更改它以使其循环并不断提示用户添加更多项目? I want it to be like a grocery list where you input the price of one item, it calculates the tax for it so that you can see the final price of that one item and the final price of all of your items together.我希望它像一个购物清单,您可以在其中输入一件商品的价格,它会计算税款,以便您可以看到该商品的最终价格以及所有商品的最终价格。 I also tried something like this but it didn't work:我也尝试过这样的事情,但没有奏效:

print("The sales tax in Lucas County is 7.25%")
sales_tax = 0.0725
price_total=0
def price(price_input, price_tax, price_semitotal, price_total): 
    price_input = float(input("Insert price of item "))
    return price_tax = price_input * sales_tax
    return price_semitotal = price_tax + price
    print("Price of that item with tax: ", price_semitotal)
    return price_total+=price_semitotal
    print("Total Price: ", price_total)

while True:
    price
print("The sales tax in Lucas County is 7.25%")
price_total=0
sales_tax = 1.0725
def price():
    price_input = float(input("Insert price of item "))

    price_tax = price_input * sales_tax
    return price_tax

while True:
    x = price()
    print(f"Price of that item with tax: {x:.2f}")
    price_total += x
    print(f"Total Price: {price_total:.2f}")
    if x == 0:
        break

sales_tax = 1.0725 está substituindo sales_tax = 1.0725 está substituindo

return price_tax = price_input * sales_tax
return price_semitotal = price_tax + price

{x:.2f} usei para usar apenas duas casas decimais. {x:.2f} usei para usar apenas duas casas decimais。

Sua base na linguagem não está boa, procure vídeos e livros para melhorar. Sua base na linguagem não está boa, procure video e livros para melhorar。

Quando price_input for igual a 0 o loop acaba. Quando price_input 用于igual a 0 o 循环阿卡巴。

This is the correct code for this but this really isn't where you should ask this sort of thing, Stack Overflow is for questions unanswered in documentation etc. What you've asked really can be picked up from documentation and tutorials这是正确的代码,但这真的不是你应该问这种事情的地方,Stack Overflow 是针对文档等中未回答的问题。你真的可以从文档和教程中获取什么

print("The sales tax in Lucas County is 7.25%")
def price(): 
    sales_tax = 0.0725
    price_total=0
    price_input = float(input("Insert price of item "))
    price_tax = price_input * sales_tax
    price_semitotal = price_tax + price_input
    print("Price of that item with tax: ", price_semitotal)
    price_total+=price_semitotal
    print("Total Price: ", price_total)

while True:
    price()

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

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