python算平均成绩_用Python计算平均成绩?
我想得到两个及格分数的平均分。输出应为:0.0,如果两个成绩都不及格<;50
如果只有一个成绩是及格分数(如果
一个大于50)
两个等级的平均值,如果两个等级都通过(如果两者都通过
大于50)
以下是我目前为止的代码:def passing_grade(grade1,grade2):
'''(number, number)--> number
This function definition prints the average of all passing grade(s)
'''
# Function 1 - If both numbers are outside the grading range (0-100)
if 0.0 < grade1 > 100.0 and 0 < grade2 > 100.0:
print ('Not available grading')
elif 0.0 >= grade1 <= 50.0 and 0.0 >= grade2 <= 50.0:
print (0.0)
#Function 2 - If one of the grades is passing then, print passing grade
elif 0.0 >= grade1 <= 50.0 and 0.0 >= grade2 >= 50.0:
print (grade2)
elif 0.0 >= grade1 >= 50.0 and 0.0 >= grade2 <= 50.0:
print (grade1)
#Function 3 - If both grades are passing >50 then print the average
elif 50.0 > grade1 <= 100.0 and 50.0> grade2 <= 100.0:
print ((grade1+grade2)/2)
本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!