定义函数message,参数有位置参数sno和name,默认参数dept(默认值为’计算机系’),可变参数scores,
可以对可变参数score求和。
def message(sno,name,dept='计算机系',*score): # 对可变参数scores进行求和,将结果赋值给result result=0 for item in score: result+=item # 通过print打印信息,输出格式可以参考下方的测试集 print("sno:"+sno+",name:"+name+",dept:"+dept+",result:{}".format(result)) if __name__ == '__main__': sign = int(input()) if sign == 0: sno=input() name = input() message(sno,name) elif sign == 1: sno = input() name = input() dept = input() message(sno,name, dept=dept) elif sign == 2: sno = input() name = input() dept = input() score1 = int(input()) score2 = int(input()) score3 = int(input()) message(sno,name, dept,score1,score2,score3)