为帖子简化了它(大多数“”是我的程序中功能齐全的实际代码):
studentName = ""
def getExamPoints (total):
"calculates examPoints here"
def getHomeworkPoints (total):
"calculates hwPoints here"
def getProjectPoints (total):
"calculates projectPoints here"
def computeGrade ():
if studentScore>=90:
grade='A'
elif studentScore>=80:
grade='B'
elif studentScore>=70:
grade='C'
elif studentScore>=60:
grade='D'
else:
grade='F'
def main():
classAverage = 0.0 # All below is pre-given/ required code
classAvgGrade = "C"
studentScore = 0.0
classTotal = 0.0
studentCount = 0
gradeReport = "\n\nStudent\tScore\tGrade\n============================\n"
studentName = raw_input ("Enter the next student's name, 'quit' when done: ")
while studentName != "quit":
studentCount = studentCount + 1
examPoints = getExamPoints (studentName)
hwPoints = getHomeworkPoints (studentName)
projectPoints = getProjectPoints (studentName)
studentScore = examPoints + hwPoints + projectPoints #(<---- heres where my problem is!)
studentGrade = computeGrade (studentScore)
main()
它一直在说:
File "/home/hilld5/DenicaHillPP4.py", line 65, in main studentScore = examPoints + hwPoints + projectPoints
TypeError: unsupported operand type(s) for +: 'NoneType' and 'NoneType'
我从来没有听说过非类型错误,甚至在google上也没有真正理解。任何认为自己了解发生了什么/知道什么是非类型的人?你知道吗
这只是Python说值是
None
(NoneType
是“值的类型None
”)。你知道吗它们之所以
None
是因为函数实际上没有return
一个值,所以分配调用函数的结果只是分配None
。你知道吗例如:
NoneType
是None
的类型。就这么简单。意思是你在做这样的事情:相关问题 更多 >
编程相关推荐