user2031682
user2031682

Reputation: 61

What's a nonetype? don't really understand

simplified it for the post (most "" is actual code in my program that is fully functional):

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()

it keeps on saying:

File "/home/hilld5/DenicaHillPP4.py", line 65, in main studentScore = examPoints + hwPoints + projectPoints

TypeError: unsupported operand type(s) for +: 'NoneType' and 'NoneType'

I've never learned about or heard of nontype errors, and even when googling it didn't really get an understanding. Anyone who thinks they understand what's happening/ know what nonetype is?

Upvotes: 1

Views: 111

Answers (2)

Michael Wild
Michael Wild

Reputation: 26331

NoneType is the type of None. Simple as that. It means that you're doing something like this:

a = b = None
c = a + b

Upvotes: 1

Amber
Amber

Reputation: 526533

That's just Python's way of saying that the values were None (NoneType is "the type of the value None").

The reason they're None is because your functions don't actually return a value, so assigning the result of calling the function just assigns None.

As an example:

>>> def foo():
...   x = 1
...
>>> print foo()
None
>>> def bar():
...   x = 1
...   return x
...
>>> print bar()
1

Upvotes: 4

Related Questions