![](/img/trans.png)
[英]How do I call a function which returns a variable, multiple times, while inside another function?
[英]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)
如何更改它以使其循環並不斷提示用戶添加更多項目? 我希望它像一個購物清單,您可以在其中輸入一件商品的價格,它會計算稅款,以便您可以看到該商品的最終價格以及所有商品的最終價格。 我也嘗試過這樣的事情,但沒有奏效:
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
return price_tax = price_input * sales_tax
return price_semitotal = price_tax + price
{x:.2f} usei para usar apenas duas casas decimais。
Sua base na linguagem não está boa, procure video e livros para melhorar。
Quando price_input 用於igual a 0 o 循環阿卡巴。
這是正確的代碼,但這真的不是你應該問這種事情的地方,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.