我们混合了一些美味的果汁。我们可以添加一定数量的一些成分。有时我们会倒一点果汁。然后我们想知道我们的果汁有哪些浓度。
例子:
- 你拿一个空罐子装果汁
- 每当罐子是空的,浓度总是 0
- 现在你添加 200 单位的苹果汁
- 然后你添加 200 单位的香蕉汁
- 现在苹果汁的浓度是0.5(50%)
- 然后你倒出 200 个单位
- 苹果汁的浓度还是50%
- 然后你再加入 200 单位的苹果汁
- 现在苹果汁的浓度是0.75,而香蕉汁的浓度只有0.25(300单位苹果汁+100单位香蕉汁)
题目难度:一般
class Jar():
def __init__(self):
#your code here
pass
def add (self, amount, kind):
#your code here
pass
def pour_out (self, amount):
#your code here
pass
def get_total_amount(self):
#your code here
pass
def get_concentration(self, kind):
#your code here
pass
jar = Jar()
assert jar.get_total_amount() == 0
assert jar.get_concentration("apple") == 0
jar.add(100, "apple")