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

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,343 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!