Python 什么是非类型?我真的不明白
简化后的代码是我程序中的实际代码,功能齐全:Python 什么是非类型?我真的不明白,python,debugging,nonetype,Python,Debugging,Nonetype,简化后的代码是我程序中的实际代码,功能齐全: studentName = "" def getExamPoints (total): "calculates examPoints here" def getHomeworkPoints (total): "calculates hwPoints here" def getProjectPoints (total): "calculates projectPoints here" def computeGrade (): if stude
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中
学生分数=examPoints+HW分数+项目分数
TypeError:不支持+:“NoneType”和的操作数类型
“非类型”
我从未了解或听说过非类型错误,甚至在谷歌搜索时也没有真正理解。任何认为自己了解发生了什么/知道什么是nonetype的人?这只是Python说值为None的方式。nonetype是值None的类型 它们为None的原因是函数实际上不返回值,因此分配调用函数的结果只分配None 例如:
>>> def foo():
... x = 1
...
>>> print foo()
None
>>> def bar():
... x = 1
... return x
...
>>> print bar()
1
这只是Python表示值为None的方式。NoneType是值None的类型 它们为None的原因是函数实际上不返回值,因此分配调用函数的结果只分配None 例如:
>>> def foo():
... x = 1
...
>>> print foo()
None
>>> def bar():
... x = 1
... return x
...
>>> print bar()
1
NoneType是None的类型。就这么简单。这意味着你在做这样的事情:
a = b = None
c = a + b
NoneType是None的类型。就这么简单。这意味着你在做这样的事情:
a = b = None
c = a + b
如果这是代码,有什么遗漏了它,所以它重新返回“无”:“code”def getExamPoints total:total=0.0,范围为4:examPoints=input Enter exam+stri+1+score for+studentName+:total+=intexamPoints total=total/.50 total=total*100“code”顺便说一句,非类型现在完全有意义了,谢谢你解释得这么好如果这是代码,有什么遗漏了它,所以它重新命名为“无”:“code”def getExamPoints total:total=0.0,范围为4:examPoints=input Enter exam+stri+1+score for+studentName+:total+=intexamPoints total=total/.50 total=total*100'code”顺便说一句,非类型现在完全有意义了,谢谢你解释得这么好