#第一题 records = [ ('foo', 1, 2), ('bar', 'Hello'), ('foo', 3, 4) ] def do_foo(x,y): print('foo',x,y) def do_bar(s): print('bar',s) #编写一个for循环,遍历records的元组 #对应执行do_foo和do_bar for tag, *content in records: if tag == 'foo': do_foo(*content) elif tag == 'bar': do_bar(*content) #第二题 items = [1, 10, 7, 4, 5, 9] #用递归对其求和 def sum(items): if len(items)==0: return 0 else: head, *tail = items return head+sum(tail) print(sum(items))