【发布时间】:2014-10-16 02:09:40
【问题描述】:
我已经有一段时间了,我被困住了。我必须编写一个程序,询问用户每个分数和平均测试分数。我需要接受五个测试分数并返回分数平均值的函数 calcAverage。确定等级,它接受分数并根据标准评分等级将等级作为字符串返回(90-100 是 A,80-89 是 B,70-79 是 C,等等)。但我还需要一个 getValidScore 函数,它提示并读取一个有效的测试分数,一旦输入分数,它就会返回到调用模块。最后是 isInValidScore 是一个函数,它检查通过的测试分数是否在 0-100 范围内,并返回一个布尔值,让我知道它是否有效。 这是我所拥有的:
def main():
test1 = int(input('Enter test grade 1: '))
test2 = int(input('Enter test grade 2: '))
test3 = int(input('Enter test grade 3: '))
test4 = int(input('Enter test grade 4: '))
test5 = int(input('Enter test grade 5: '))
grade = (test1 + test2 + test3 + test4 + test5)
input('press enter to continue')
print(calc_average)
print(determine_grade)
print(getValidScore)
print(isInvalidScore)
return;
def calcAverage():
grade / 5
return averageScore
def determinGrade(score):
if grade >= 90 and grade <= 100:
return 'A'
elif grade >= 80 and grade <= 89:
return 'B'
elif grade >= 70 and grade <= 79:
return 'C'
elif grade >= 60 and grade <= 69:
return 'D'
else:
return 'F'
def getValidScore():
grade = int(input('input score'))isInvalidScore(score)
while isInvalidScore == false:
print('ERROR')
grade = int(input('input correct score'))
return score
def isInvalidScore(score):
status = True
if score < 0 or score > 100:
status = True
else: status = False
return status
main()
所以我添加了回报,当我运行程序时,我得到了这个:
进入测试等级1:99
进入测试等级2:88
进入测试等级3:77
进入测试等级4:66
进入测试等级5:55
按回车键继续
函数 calc_average 在 0x02BAD228>
函数确定等级在 0x02BAD270>
函数 getValidScore 在 0x02BAD2B8>
function isInvalidScore at 0x02BAD300>
【问题讨论】: