[英]My function get_subtotal should be adding all product price, what I am doing wrong with the loop?
函数get_subtotal
- 对每种产品的价格get_subtotal
并返回 函数get_tax
- 返回小计的 6.5% 函数get_total
- 返回小计加上税款
这些都在 Class 里面。
class Order():
def __init__(self):
self.id = ""
self.products = []
def get_subtotal(self):
self.total = 0
for item in self.products:
self.total += 1
return self.total
def get_tax(self):
return self.total * 0.065
def get_total(self):
return self.total + self.get_tax()`
尝试更改get_subtotal
方法中的get_subtotal
,如果将return
语句放在for
循环中,它将仅返回第一项!。 但是还是不明白,因为你的方法只计算产品列表的长度,也许是这样的?
def get_subtotal(self):
self.total = 0
for item in self.products:
self.total += item
return self.total
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.