【发布时间】:2020-05-21 06:10:02
【问题描述】:
我不知道如何使用随机包打印学生的成绩而不复制其他学生的相同成绩。该程序需要功能来制作。请帮忙
import random
def get_values():
list = []
q = 1
i = 4
for num in range(i):
data = random.randint(1, 100)
list.append(data)
#print("Quiz no.", q)
#print(data)
q += 1
return list
def validate(ctr):
while ctr > 50:
print("Maximum of 50 students only")
exit()
return ctr
def grade(x):
FG = sum(x) / 4
return FG
def EQ(FG):
if FG < 60:
s = float(5.0)
print(s)
elif FG >= 60 and FG < 75:
s = float(3.0)
print(s)
elif FG >= 75 and FG < 90:
s = float(2.0)
print(s)
elif FG >= 90 and FG <= 100:
s = float(1.0)
print(s)
return s
def main():
list_high = []
list_low = []
ls=[]
repeat = 'Y'
ctr = 1
while repeat.upper() == 'Y':
validate(ctr)
x = get_values()
y = grade(x)
z = EQ(y)
high = list_high.append(max(x))
low = list_low.append(min(x))
print("Student # Quiz 1 Quiz2 Quiz 3 Quiz4 Grade EQ")
q = 1
for num in range(ctr - 1):
print("\n ", q, end='')
for c in range(len(x)):
print(" ", x[c], end="")
q += 1
print(" ", y, " ", z, end=" ")
ctr += 1
# average_high = sum(list_high) / len(list_high)
#average_low = sum(list_low) / len(list_low)
repeat = input("\n Enter Y to input another students score: ")
main()
我的程序的输出
学生 # 测验 1 测验 2 测验 3 测验 4 年级 EQ
1 17 95 5 92 52.25 5.0
2 17 95 5 92 52.25 5.0
3 17 95 5 92 52.25 5.0
4 17 95 5 92 52.25 5.0
5 17 95 5 92 52.25 5.0
6 17 95 5 92 52.25 5.0
输入 Y 输入另一个学生的分数:
【问题讨论】:
标签: python