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

Miguel Soriano
seal-mask
.a{fill-rule:evenodd;}techdegree
Miguel Soriano
Front End Web Development Techdegree Student 3,895 Points

Need help for coding challenge square root

Hi everyone if anyone can help me with the coding challenge, my code seem to work in the "launch workspace" but in the coding challenge i keep getting an error. The challege is: "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. (A square is the value multiplied by itself. eg: The square of 5 is 25. 25=5x5)"

squaring.py
def square(number):
 return calculate_square_root 

ask_number= 5
store_number= ask_number
calculate_square_root= ask_number * ask_number
print("A square is the value {} multiplied by itself {}.".format(store_number, calculate_square_root))

2 Answers

Viraj Deshaval
Viraj Deshaval
4,874 Points

This is because you are using return with print. Remove print it will work. Also as per the challenge you need to assign to result variable.

result = square(3)
Viraj Deshaval
Viraj Deshaval
4,874 Points

Hi Miguel, Challenge is very simple. What it's asking you is to create a function named square with one parameter and your function should create a square of number you pass and return the squared number. Advice: Always perform any task you want to do within your function its always good your function return something.

In general squaring a number means multiply the number by itself I. E. 5*5 this will give you 25. Try it out and let me know if you still require help. I know you can do it. It's hardly a 3 line of code go for it!

Miguel Soriano
seal-mask
.a{fill-rule:evenodd;}techdegree
Miguel Soriano
Front End Web Development Techdegree Student 3,895 Points

Hi Viraj thanks for the reply, currently I am using this code def square(number): return print(number * number) square(5)

but I still get this error: Bummer: AssertionError: None != 0 : Uh oh, seems like your math might be off for the argument 0, try again