下面的代码似乎仅对第一个学生具有语义功能,因为他的成绩是正确计算的。对于第二个学生,它不计算预期成绩。另一个问题是如何从for循环中打印迭代器,以便得到提示符:
输入评估名称1:
输入评估名称2:
等...
assessment=[]
weight=[]
assign_number = int(input('How many assessment : '))
def main():
for i in range(assign_number):
asses_name =input('Enter name of assessment: ')
assessment.append(asses_name)
asses_value =int(input('How many marks is the ' + assessment[i] + ' worth : '))
weight.append(asses_value)
if sum(weight)!= 100:
del weight[:]
print("the total is not 100, please re enter")
main()
else:
student_details()
def calculatedgrade(score):
if 100<= score:
grade = 'High Distiction'
elif 80 <= score <= 100:
grade = 'High Distiction'
elif 70 <= score <= 79:
grade = 'Distiction'
elif 60 <= score<= 69:
grade ='Credit'
elif 50 <= score <= 59:
grade = 'Pass'
elif score <=50:
grade = 'Fail'
return grade
def student_details():
student_name =[]
student_mark =[]
marks=[]
total_mark=[]
student_number = int(input('How many students : '))
for n in range(student_number):
name = input('What is the name of student: ')
student_name.append(name)
for m in range(assign_number):
mark = input('what did ' + format(student_name[n])+' get out of
' +format(weight[m]) +' in the ' +assessment[m] +' ?')
marks.append(mark)
score = int(marks[m])/int(weight[m])*100
student_mark.append(score)
calculatedgrade(score)
print(mark,' out of ',weight[m],'is a ',(calculatedgrade(score))
main ()
答案 0 :(得分:0)
打印计数器:打印连接到 i 的当前显示字符串。像这样:
stringForInput = 'Enter name of assessment '
for i in range(assign_number):
stringForInput = stringForInput + str(i+1) + ' :'
asses_name =input(stringForInput)