作业1
import random
#引入随机数模块
xing=["小白","小黄","小王","小陈","小绿"]
print("学号\t\t\t姓名\t\tJava\tC语言\tpython\t平均成绩\t")
listj=[]
listc=[]
listp=[]
lista=[]
for i in range(5):
#循环5次
n = 20170000 + random.randint(0, 9999)
j = random.randint(60, 100)
listj.append(j)
#放在数组最末端
c = random.randint(60, 100)
listc.append(c)
p = random.randint(60, 100)
listp.append(p)
ave = (j + c + p) / 3
print("%d\t%s\t\t%d\t\t%d\t\t%d\t\t%.2f" % (n, xing[i], j, c, p, ave))
ja = listj[0] + listj[1] + listj[2] + listj[3] + listj[4]
ja = ja / 5
lista.append(ja)
print(" Java平均成绩:", fORMat(ja))
ca = listc[0] + listc[1] + listc[2] + listc[3] + listc[4]
ca = ca / 5
lista.append(ca)
print(" C语言平均成绩:", format(ca))
pa = listp[0] + listp[1] + listp[2] + listp[3] + listp[4]
pa = pa / 5
lista.append(pa)
print("Python平均成绩:", format(pa))
Max = max(lista)
Min = min(lista)
print("最大值为:{}\n最小值为{}".format(Max, Min))
作业2:
def tempConvert():
t = input("请输入数值:")
R = ["RMB","rmb"]
U = ["USD","usd"]
try:
eval(t[3:])
except NameError:
print("错误,第四位开始请输入整数")
if t[0:3] in R:
temp = float(t[3:])/6
temp = "{:.2f}".format(temp)
temp = "USD" + str(temp)
print("结果:",temp)
elif t[0:3] in U:
temp = float(t[3:])*6
temp = "{:.2f}".format(temp)
temp = "RMB" + str(temp)
print("结果:",temp)
else:
print("输入格式错误")
return False
return temp
tempConvert()