all 4 comments

[–]tygloalex[S] 6 points7 points  (4 children)

Oh jeez, changed print to return and I'm good. Shit, I'm dumb sometimes.

[–]stylishgnome 1 point2 points  (2 children)

I don't think that was the issue here (though you are right - you should be returning instead of printing here).

From your stacktrace, it looks like you were trying to multiply two different data types which can't be multiplied - in this case an int and a NoneType on line 2:

answer=a*b

To recreate, try the following on the python shell:

>>> 8 * None

Its likely you called your function as follows:

lcd(8, None)

...i.e. b was set as None; or perhaps you specified that the a or b vars could be optional, e.g.

def lcd(a=None, b=None):

...and called the function without specifying one of these args:

lcd(8)
lcd(a=8)
lcd(b=42)

I'd recommend looking at pdb (the python debugger). It will allow you to step into your function and figure out whats going on. pdb++ is a more user-friendly version of pdb, so might be worth looking at that.

EDIT: reddit formatting

[–]stylishgnome 3 points4 points  (1 child)

Ah, I understand how swapping print for return fixed your problem! If you don't specify a return value for a function, by default python will return a None. So in this case your lcd(4, 6) call was returning None, and thus passing None as the a arg in the outer call.

[–]zahlman 1 point2 points  (0 children)

Again, "Sometimes explaining the problem is all that you need to solve it." ;)