我应该写一个程序来确定字母等级(a、B、C、D、F),跟踪通过和不通过的学生人数,并显示班级平均成绩。让我感到困惑的一点是“该程序将能够处理用户在本课程中指示的任意数量的学生。”如何创建无限的输入-用户想要多少就有多少
我基本上有一个应该做什么的框架,但我一直在思考如何创建用户想要的尽可能多的输入,然后在其他函数中使用这些信息(如何将所有这些信息输入到另一个函数中)
如果你们中有人能告诉我如何创建无限数量的输入,我将不胜感激!!祝你们今天愉快,伙计们!:)
我的代码:
studentScore = input("Grade for a student: ")
fail = 0
def determineGrade (studentScore):
if studentScore <= 40:
print 'F'
elif studentScore <= 50:
print 'D'
elif studentScore <= 60:
print 'C'
elif studentScore <= 70:
print 'B'
elif studentScore <= 100:
print 'A'
else:
print 'Invalid'
def determinePass (studentScore):
for i in range():
if studentScore <= 40:
fail += 1
else:
Pass += 1
def classAverage (studentScore):
determineGrade(studentScore)
determinePass(studentScore)
无限输入可以使用
while loop
完成。您可以将该输入保存到其他数据结构(如列表)中,但也可以将代码放在下面试试这个
EOFError-如果从文件中获取输入,则会出现此错误
值错误-以防提供错误输入
要无限次地请求数据,您需要一个while循环
相关问题 更多 >
编程相关推荐