【发布时间】:2019-09-18 13:39:56
【问题描述】:
创建一个程序,计算学生在使用加权成绩簿的班级中的成绩。
加权系统使用百分比来确定每个分配类别的价值。对于此项目,请使用以下百分比:
- 项目成绩 = 30%(重量 = .30)
- 参与分数 = 20%(权重 = .20)
- 测验 = 10%(重量 = .10)
- 考试 = 40%(重量 = .40)
评分标准:
- A - 90-100
- B - 80-89
- C - 70-79
- D - 60-69
- F - 低于 60
注意:您将每个类别的平均值乘以其权重。最终成绩是计算权重的总和。
无法获取允许用户在所有 4 个类别中输入成绩的代码,因为它卡在选择的第一个类别上,并且循环一直在继续,而不会停止询问分数列表。我尝试了一个循环内的循环,但它也只在第一个选择的循环上继续。需要在所有 4 个类别中输入多个等级,这就是为什么我需要程序允许用户输入其他类别的等级,而不仅仅是首先选择的类别。
print ("Weighted Grade Calculator ")
name = input("Enter the Student's Name ")
number = input("Enter the Student's Number ")
x = input("Enter Assignment type: ")
c = 'y'
#Loop is in case user wants to calculate another students grade
while c=='y' or c=='Y':
if x >= "quiz" or x >= "Quiz":
input_string = input("Enter a list of scores separated by space ")
#Read ints separated by spaces
lst = input_string.split()
print("Calculating sum of element of input list")
#convert strings to ints and convert map to list
lst = list(map(int, lst))
#Find total and avg
total = sum(lst)
avg_1 = total/len(lst)
elif x >= "project" or x >= "Project":
input_string = input("Enter a list of scores separated by space ")
lst = input_string.split()
print("Calculating sum of element of input list")
lst = list(map(int, lst))
total = sum(lst)
avg_2 = total/len(lst)
elif x >= "participation" or x >= "Participation":
input_string = input("Enter a list of scores separated by space ")
lst = input_string.split()
lst = list(map(int, lst))
total = sum(lst)
avg_3 = total/len(lst)
elif x >= "exam" or x >= "Exam":
input_string = input("Enter a list of scores separated by space ")
lst = input_string.split()
print("Calculating sum of element of input list")
lst = list(map(int, lst))
total = sum(lst)
avg_4 = total/len(lst)
else:
print("error, please try again")
#Finds percentage earned from each category
w_quiz = avg_1 * 0.1
w_project = avg_2 * 0.3
w_participation = avg_3 * 0.2
w_exams = avg_4 * 0.4
total = w_project + w_quiz + w_participation + w_exams
if(total >= 90 and total <=100):
grade = 'A'
elif(total >= 80 and total < 90):
grade = 'B'
elif(total >= 70 and total < 80):
grade = 'C'
elif(total >= 60 and total < 70):
grade = 'D'
elif(total >= 0 and total < 60):
grade = 'F'
print ("Student Name: " + str(name))
print ("Student ID: " + str(number))
print ("Total Weighted Score: " + str(total) + "%")
print ("Letter Grade: " + grade)
c = input("Would you like to calculate another grade? (Y or N): ")
【问题讨论】:
-
没有运气是什么意思?你能举一个输入、预期输出和实际输出的例子吗?
-
@foobarbaz 基本上我需要在每个类别(测验、考试、参与和项目)中输入多个等级。假设我为第一个输入输入了测验,然后成绩进入一个列表,该列表只输入了其他测验成绩,然后程序询问我是否要输入另一个成绩,我说“是”,但这次我进入该类别的考试, 输入的成绩应该放在一个仅由考试成绩组成的不同列表中。
标签: python python-3.x