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

Kim Raffield
Kim Raffield
276 Points

Understanding what it means to create a function that defines a single parameter

I seem to be stuck on https://teamtreehouse.com/library/python-basics-3/functions-and-looping/create-a-function

I've been re-watching the associated video just before this exercise, but I am not understanding how to create a function named square and assign it a single parameter named number.

In comparing it to the code from the previous exercise, I think my misunderstanding is not being able to translate what I did previously to this new exercise.

Any guidance on how to execute and fully understand this exercise is much appreciated.

squaring.py
def square(number)
 number = 5 * 5
    return square
def func(param):
  pass

^ that's an example of a func w/ a parameter. You've mostly done that right. Your issue is moreso how to use the value pased into the func.

1 Answer

  • First, define the function heading. You got it right: it's def square(number). Just don't forget to put a colon after the closing parenthesis
  • The body is incorrect. The lines must be properly indented, and it should look like the following:
return number * number