第一题:
import random#初始化 No=[] Javaaverage=[] Caverage=[] Pythonaverage=[] Averageaverage=[] #随机生成学号 print("学号\t\t\t姓名\t\tjava\tC语言\tPython\t平均成绩\t") name=['小谢','小祥','小辉','小知','小离'] for i in range(5): No= 20170000 + random.randint(0, 9999) a = random.randint(60, 100) Javaaverage.append(a) b = random.randint(60, 100) Caverage.append(b) pythonaverage = random.randint(60, 100) Pythonaverage.append(pythonaverage) averageaverage=(a+b+pythonaverage)/3 Averageaverage.append(averageaverage) print("%d\t%s\t\t%d\t\t%d\t\t%d\t\t%.2f\t\t"%(No,name[i],a,b,pythonaverage,averageaverage)) print("Java平均成绩:") average_Javaaverage=(Javaaverage[0]+Javaaverage[1]+Javaaverage[2]+Javaaverage[3]+Javaaverage[4])/5 print(average_Javaaverage) print("C语言平均成绩:") average_Caverage=(Caverage[0]+Caverage[1]+Caverage[2]+Caverage[3]+Caverage[4])/5 print(average_Caverage) print("Python平均成绩:") average_Pythonaverage=(Pythonaverage[0]+Pythonaverage[1]+Pythonaverage[2]+Pythonaverage[3]+Pythonaverage[4])/5 print(average_Pythonaverage) Max=max(Pythonaverage) Min=min(Pythonaverage) average_Python=(Pythonaverage[0]+Pythonaverage[1]+Pythonaverage[2]+Pythonaverage[3]+Pythonaverage[4])/5 print("Python平均成绩:%.2f\t\tPython成绩最高为:%.2f\t\tPython成绩最低为:%.2f\t\t"%(average_Python,Max,Min))
https://gitee.com/qbz140258/knowing_and_leaving/commit/0c143a10418b11e8aae41db03b1117bd36147e95
第二题:
print("请输入以Y或$表示的金额:") cash=input() try: eval(cash[1:]) except NameError: print("错误,第二位开始请输入整数") except SyntaxError: print("错误,第二位开始请输入整数") if cash[0] in ['Y']: cashy = eval(cash[1:]) / 6 print("${:.2f}".format(cashy)) elif cash[0] in ['$']: money = 6 * eval(cash[1:]) print("Y{:.2f}".format(money)) else: print("错误,第一位输入Y或$")
https://gitee.com/qbz140258/knowing_and_leaving/commit/4ddd2e945399d2d57dc9b373cc5e8f454df31406