我必须创建一个程序,收集成绩,取平均值,然后打印最高和最低的平均值以及用户名。我正在使用前一周作业中的代码,该代码接受用户输入并计算平均值,但我正在努力找出如何从计算出的平均值中检测高/低值。我也不确定在检测到这些高/低值后,从何处开始重新打印相关的名称信息。任何帮助都将不胜感激!你知道吗
def main():
numuser=eval(input("How many users are there?: "))
numgrade=eval(input("How many grades will there be for each user?: "))
usercount=0
gradecount=0
grade(numuser,numgrade,usercount,gradecount)
def grade(nu,ng,uc,gc):
name=[]
while uc <= nu:
first=input("Please enter the student's first name: ")
last=input("Please enter the student's last name: ")
name.append(last)
ID=input("Please enter the student's ID: ")
gradetot=0
total=[]
grades=[]
while gc < ng:
gradeval=eval(input("Please enter the grade: "))
total.append(gradeval)
gradetot=gradetot+gradeval
gc=gc+1
avg=gradetot/gc
grades.append(avg)
low=min(grades)
high=max(grades)
nu=nu-1
uc=uc+1
gc=0
print("The average grade for", first, last, ID, "is :", avg)
if uc>nu:
print("The lowest average is ", low, "and the highest average is", high)
main()
你必须把学生姓名和平均成绩的数据储存在字典里。然后可以使用字典方法进行检索
如果你想打印用户名和他们的成绩信息,你必须把他们存储在字典里
def main():
def grade(nu,ng,uc,gc): dct={} while uc < nu: first=input("Please enter the student's first name: ") last=input("Please enter the student's last name: ") ID=input("Please enter the student's ID: ") gradetot=0
""" nu=nu-1 uc=uc+1 gc=0
“”“
相关问题 更多 >
编程相关推荐