[英]My function get_subtotal should be adding all product price, what I am doing wrong with the loop?
Function get_subtotal
- Sums the price of each product and returns it Function get_tax
- Returns 6.5% times the subtotal Function get_total
- Returns the subtotal plus the tax函数
get_subtotal
- 对每种产品的价格get_subtotal
并返回 函数get_tax
- 返回小计的 6.5% 函数get_total
- 返回小计加上税款
these are inside the Class.这些都在 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()`
Try changing the identation in get_subtotal
method, if you put the return
stament inside the for
loop it will return only the first item!.尝试更改
get_subtotal
方法中的get_subtotal
,如果将return
语句放在for
循环中,它将仅返回第一项!。 But still not understanding, because your method only count the lenght of the products lists, maybe is some like this?但是还是不明白,因为你的方法只计算产品列表的长度,也许是这样的?
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.