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

TASK 1:2 AFTER CHECK_PLEASE.PY

Challenge Task 1 of 2 Create a function named square. It should define a single parameter named number.

In the body of the function return the square of the value passed in.

im so lost :( im not asking for answers, but do you guys think you can help me find the topic in which this was discussed at least? or some sort of quick tutoring..

so far I want to

def function_name (square) ????? but I keep getting an F on that so OBVIOULSY NOT THAT

1 Answer

Eric M
Eric M
11,545 Points

Hi Jazmin, Let's take a look at each component of this task. Create a function named square. It should define a single parameter named number.

Create a function named square. Functions are created (or defined) with the keyword def and a function name is its identified that follows the def keyword, doesn't have spaces, and ends in parentheses.

def square():

It should define a single parameter named number Parameters (which are sometimes referred to as arguments) are the variables that go inside the parentheses, and they can be used by the function based on their name. So if I had a function that looked like:

def draw_circle(radius_in_pixels, color):

The function name is make_paper, it has one two parameters the first is named radius_in_pixels and the second is named color

If I call the function somewhere else in my program I would do it as below. When we call the function we include arguments in the function call, the values of our arguments become the values of the parameters within the function

draw_circle(5, "green")

So within our function:

def draw_circle(radius_in_pixels, color):
        # radius_in_pixels would be equal to an integer of value 5, if called as above
        # color is a string containing "green", if called as above
        # for instance, we might write:
        diameter_in_pixels = radius_in_pixels * 2