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 Functions and Looping Create a Function

Squaring.py Challenge

How do I call a new function and pass it a new variable? I am on part two of the challenge and I created a function that squares a number entered.

squaring.py
def square(number):
    return(number * number)

2 Answers

To call a function with an argument, just put the argument between the parens. e.x.:

def square(number):
    return number * number

# The below line calls the function "square", but it doesn't do anything with
# the returned value:
square(3)

If you merely call square, however, it will only return the value 3. What happens to 3? Well, it isn't being used, or stored within a variable, so it's kind of just floating in space. To assign it to a variable, you could write this:

result = square(3)

I hope this helps! :grin:

yes it does thank you so much!

If it helped, remember to provide a "Best Answer" :wink:

on the next step it is asking to store the value from the function call but im not sure how to do that i tried this but its not working import math

def square(number): return (number * number)

result = square(number)

square(3)