如何在python中求分数对应等级_如何使用Python中的列表和函数计算类的等级

我需要编写一个程序,根据以下输入和过程计算一个班级的成绩:询问用户课程中的测试、作业、测验和实验室的数量。

询问用户是否有与上述测试不同的期末考试,例如,一个课程有2个测试,每个测试的权重为12.5%,1个期末考试的权重为15%。

对于每个类别都有一个数字>0a。提示用户输入加权百分比,即所有类别的加权百分比应为100%!!!b、 获取该类别的分数。c、 如果类别是实验室,则将所有分数相加。d、 否则,平均得分。e、 计算类别的加权平均数。

用每个类别的加权平均数计算课程的成绩。

询问用户是否要计算另一个班级的成绩。

如果用户回答是,则返回步骤1。7否则,结束程序。

我几乎完成了程序和我的所有功能,但我有困难,使所有的结合起来,并正常工作。我的第一个问题是合并步骤5/6并让while循环与其余代码一起工作。此外,我很难将实验室的分数相加,并将其纳入加权平均数。在

非常感谢任何帮助!在

这是我的代码:def main():

inputList = get_user_input()

average = get_scores(inputList)

weightedAvgs = get_weightedavg(average, inputList)

results = get_class_grade(weightedAvgs)

ans = "yes"

while(ans == "yes"):

def get_user_input():

inputList = [] # initializes a list

# Gets how many scores for each category the user would like to enter and adds value to a list

tests = int(input("How many tests scores would you like to enter? "))

inputList.append(tests)

assignments = int(input("How many assignment scores would you like to enter: "))

inputList.append(assignments)

quizzes = int(input("How many quiz scores would you like to enter? "))

inputList.append(quizzes)

labs = int(input("How many lab scores would you like to enter? "))

inputList.append(labs)

final = int(input("How many final scores would you like to enter? "))

inputList.append(final)

# Gets the weight of each category if there are any scores to enter and adds the value to a list

if tests > 0:

testWeight = float(input("Enter the weight of tests: "))

inputList.append(testWeight)

else:

testWeight = 0

if assignments > 0:

assignmentWeight = float(input("Enter the weight of assignments: "))

inputList.append(assignmentWeight)

else:

assignmentWeight = 0

if quizzes > 0:

quizWeight = float(input("Enter the weight of quizzes: "))

inputList.append(assignmentWeight)

else:

quizWeight = 0

if labs > 0:

labWeight = float(input("Enter the weight of labs: "))

inputList.append(labWeight)

else:

labWeight = 0

if final > 0:

finalWeight = float(input("Enter the weight of the final: "))

inputList.append(finalWeight)

else:

finalWeight = 0

return(inputList)

def get_scores(inputList):

# Gets scores for each category & calculates avg for each category

average = []

testScoreList = []

tests2 = inputList[0]

for x in range(tests2):

testScore = float(input("Enter your test score: "))

testScoreList.append(testScore)

if tests2 == 0:

testAvg = 0

else:

testAvg = sum(testScoreList) / inputList[0]

average.append(testAvg)

assignmentScoreList = []

assignments2 = inputList[1]

for x in range(assignments2):

assignmentScore = float(input("Enter your assignment score: "))

assignmentScoreList.append(assignmentScore)

if assignments2 == 0:

assignmentAvg = 0

else:

assignmentAvg = sum(assignmentScoreList) / inputList[1]

average.append(assignmentAvg)

quizScoreList = []

quizzes2 = inputList[2]

for x in range(quizzes2):

quizScore = float(input("Enter your quiz score: "))

quizScoreList.append(quizScore)

if quizzes2 == 0:

quizAvg = 0

else:

quizAvg = sum(quizScoreList) / inputList [2]

average.append(quizAvg)

labScoreList = []

labs2 = inputList[3]

for x in range(labs2):

labScore = float(input("Enter your lab score: "))

labScoreList.append(labScore)

if labs2 == 0:

labSum = 0

else:

labSum = sum(labScoreList)

average.append(labSum)

finalScoreList = []

final2 = inputList[4]

for x in range(final2):

finalScore = float(input("Enter the score for your final: "))

finalScoreList.append(finalScore)

if final2 == 0:

finalAvg = 0

else:

finalAvg = sum(finalScoreList) / inputList[4]

average.append(finalAvg)

def get_weighted_avg(average, inputList):

weightedAvgs = []

weightedTestAvg = average[0] * inputList[5]

weightedAvgs.append(weightedTestAvg)

print("Your weighted average is " + str(weightedTestAvg))

weightedAssignmentAvg = average[1] * inputList[6]

weightedAvgs.append(weightedAssignmentAvg)

print("Your weighted average is " + str(weightedAssignmentAvg))

weightedQuizAvg = average[2] * inputList[7]

weightedAvgs.append(weightedQuizAvg)

print("Your weighted average is " + str(weightedAssignmentAvg))

weightedLabSum = average[3] * inputList[8]

weightedAvgs.append(weightedLabSum)

print("The sum of your lab scores are " + str(weightedLabAvg))

weightedFinalAvg = average[4] * inputList[9]

weightedAvgs.append(weightedFinalAvg)

print("Your weighted average is " + str(weightedFinalAvg))

return(weightedAvgs)

def get_class_grade(weightedAvgs):

grade = weightedAvgs[0] + weightedAvgs[1] + weightedAvgs[2] + weightedAvgs[3] + weightedAvgs[4]

if grade >= 90:

finalGrade = "A"

elif grade >= 80:

finalGrade = "B"

elif grade >= 70:

finalGrade = "C"

elif grade >= 60:

finalGrade = "D"

else:

finalGrade = "F"

print("Your grade is " + finalGrade)

ans = (input("Would you like to calculate a grade for another class? "))

while(ans != "yes" and ans != "no"):

print("Please type yes or no")

ans = (input("Would you like to calculate a grade for another class? "))

if ans == "no":

exit()

main()

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值