Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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.

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:

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)