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!

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

Working on the create a function task and am having a difficult time trouble - shooting... >_<

I've been working on this task for a while now. Wrote this so far and when I check the work, it gives me and End of File error. I really do not know what I messed up on, any insight would be helpful. Also, I put this into the work space and it ran fine. Any suggestions?

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

number = int(input("What number would you like to square?"))
answer = square(number)

print("The square of {} is {}. {} = {} x {}!".format(number, answer, answer, number, number))

1 Answer

Philip Schultz
Philip Schultz
11,437 Points

Hey Michael, This challenge is asking for two parts. The first part (task 1 of 2) Is asking you to make a function called 'square'. This function will have one parameter called 'number', then it will return the square of that number. see code below.

def square(number):
    return number**2 
# NOTE: return number**2 - is how you raise to the power of 2. (if you wanted you could just return number * number)

Task 2 of 2, is asking you to simply call the function and to give it the argument of '3', then store the result in a variable called 'result'.

result = square(3)

Thank you very much! I kinda feel a little bit stupid now for not seeing that I only had to create a function... I knew that I was overthinking something :D. Anyways, thanks again :3!