旅行的账一行一笔:花在哪一类和多少元,比如 "food 30"。写 biggest_spend(text):同一类加在一起,返回花钱最多的那一类。没有账就返回 None(模板写好了)。不会有两类一样多。
biggest_spend("food 30\nbus 12\nfood 25\nhotel 50")→'food'biggest_spend("")→Nonedef biggest_spend(text):
if text == "":
return None
spent = {}
for line in text.splitlines():
kind, money = line.split()
# 在这里写:把这一笔加到这一类的总数上
# 在这里写:return 总数最大的那一类
return None
写好了先点「运行」试试示例,没问题再点「提交」。