将其简化为帖子(大多数“”是我的程序中完全正常运行的实际代码):
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()
继续说:
文件“/home/hilld5/DenicaHillPP4.py”,第65行,在main中 studentScore = examPoints + hwPoints + projectPoints
TypeError:+不支持的操作数类型:'NoneType'和 'NoneType'
我从来没有学过或听说过非类型错误,即使用谷歌搜索它也没有真正理解。有谁认为他们了解发生了什么/知道什么是非类型?
答案 0 :(得分:4)
这就是Python的方式,即值为None
(NoneType
是“值None
的类型”)。
他们None
的原因是因为你的函数实际上并没有return
一个值,所以分配调用函数的结果只会赋予None
。
举个例子:
>>> def foo():
... x = 1
...
>>> print foo()
None
>>> def bar():
... x = 1
... return x
...
>>> print bar()
1
答案 1 :(得分:1)
NoneType
是None
的类型。就那么简单。这意味着你正在做这样的事情:
a = b = None
c = a + b