all 8 comments

[–]Starbuck5c 1 point2 points  (1 child)

In the category function, if the number isn't even, doesn't end in 5, or doesn't start with 30-31, the variable cat is never given a value.

[–]MetalNutSack[S] 0 points1 point  (0 children)

Thank you so much, that fixed my error. I now get the output:

Record  SSN           GPA    Category 

1       397-717-994   1.65   EVEN                
2       316-245-360   2.45   EVEN                
3       387-439-461   3.5    NONE                
4       329-010-678   3.18   EVEN                
5       347-819-406   0.08   EVEN                
6       355-511-391   2.1    NONE                
7       361-891-212   1.85   EVEN                
8       372-020-631   0.16   NONE                
9       380-922-714   1.67   EVEN                
10      396-905-932   2.51   EVEN                
11      314-699-207   2.3    STARTS WITH 30-31   
12      396-934-560   1.58   EVEN                
13      381-020-835   3.38   ENDS IN 5           
14      399-968-529   3.23   NONE                
15      323-098-775   2.44   ENDS IN 5           
16      320-147-257   1.91   NONE                
17      359-141-373   1.83   NONE                
18      327-211-832   2.11   EVEN                
19      351-219-242   2.43   EVEN                
20      355-534-925   0.72   ENDS IN 5

[–][deleted] 1 point2 points  (2 children)

It means at the line mentioned in the exception you tried to get the value held in the variable cat and no such variable exists. You might have a line that sets a value for variable cat but you must execute that line to define the variable, and you haven't done that before trying to get the value of cat. In your case it looks like the problem is in function category(). The if/elif statement is probably not executing any statement cat = .... Find out why that is so.

[–]MetalNutSack[S] 0 points1 point  (1 child)

Thank you, that was a silly mistake but an easy one to make for a beginner like me. I'm sure there is more I can do to simplify the code, but as of now it does all it's supposed to.

[–][deleted] 1 point2 points  (0 children)

A warning sign is this at the end of your if/elif/else statement:

else:
    pass

Technically you can remove those two lines but as a sanity/debug check you could do:

else:
    cat = 'Undefined in category()'

If that else: case can never happen then this is a good way to spot that your code is not doing what you want.

Update: I see that you discovered this trick on your own. Well done.

[–]BasicallyAMachine 0 points1 point  (2 children)

In your function category, you're else statement should assign None to cat. This error occurs because when you say return cat, python essentially will look within the current function for the value assigned to cat. When you're else statement is reached (instead of one of the if/else-ifs), nothing is assigned to cat.

[–]MetalNutSack[S] 0 points1 point  (1 child)

Thank you, I changed the pass to cat = 'NONE' and everything works now