Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Python Basics (2015) Logic in Python Product

What is the answer? I don't know if I'm doing the multiplication correctly because this language is chaos.

Should I be putting the result of it into a variable? Is there a math function I didn't use properly? I don't remember from earlier videos and I don't want to have to search for it to figure out how simple math works. I'm operating under the assumption python knows the difference between values... because that's how this language is sold so... what did i do wrong here?

product.py
def product(num1, num2):
    num1 * num2 
    return
product(2,4)

2 Answers

Bapi Roy
Bapi Roy
14,237 Points
def product(num1, num2):
    return num1 * num2 

product(2,4)

This is correct format

Sławomir Lasik
Sławomir Lasik
7,792 Points

In function You do not store anywhere the product from num1 * num2 operation. This can be done by either assigning this to a new variable

prod = num1 * num2

or returning instantly

return num1 * num2

return in the last statement of your function will return None. After return you must give what you want to return

def prod(num1, num2):
    prod = num1 * num2
    return  # this will return None and thus None printed on Your console

print(prod(2, 3))