starletkiss 2020-07-08
输入
输出
string = input() #将输入字符串转换为字典作为函数关键字参数传入 l = string.split(‘,‘) d = {} d[‘语文‘] = int(l[0]) d[‘数学‘] = int(l[1]) d[‘英语‘] = int(l[2]) for i in l[3:]: d[i.split(‘=‘)[0]]=int(i.split(‘=‘)[1]) #定义函数实现分班 def main(**kwargs): sum = 0 count = 0 for k,v in kwargs.items(): sum += v count += 1 avg = sum / count if "物理" in kwargs: if avg > 90 and kwargs.get("数学") >= 80: print("平均分是:{:.2f},分配班级是:{}".format(avg,"理科A班")) elif avg <= 90 and avg >= 80 or (avg > 90 and kwargs.get("数学") < 80) or (avg > 90 and kwargs.get("物理") >= 70): print("平均分是:{:.2f},分配班级是:{}".format(avg,"理科B班")) else: print("平均分是:{:.2f},分配班级是:{}".format(avg,"理科C班")) else: if avg > 90 and kwargs.get("语文") >= 80: print("平均分是:{:.2f},分配班级是:{}".format(avg,"文科A班")) elif avg <= 90 and avg >= 80 or (avg > 90 and kwargs.get("语文") < 80) or (avg > 90 and kwargs.get("政治") >= 70): print("平均分是:{:.2f},分配班级是:{}".format(avg,"文科B班")) else: print("平均分是:{:.2f},分配班级是:{}".format(avg,"文科C班")) #调用函数运行 if __name__ == ‘__main__‘: main(**d)