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

my code is working workspace but not in test

squaring.py
def square(number):

    return ( number *number)

enter_no = int(input( "enter the no?   "))

sq_no = square(enter_no)
print("the sq of{} is{}".format(enter_no,sq_no))

1 Answer

boi
boi
14,242 Points

When solving a challenge, make sure you don't add anything extra or less, because the challenge requires you to solve it as per the instructions, nothing more or less.

In your case, you've added extra code.

def square(number):

    return ( number *number)

enter_no = int(input( "enter the no?   "))👈#No instructions, to create an input variable named "enter_no" << Invalid code

sq_no = square(enter_no) 👈#No instructions, to create a variable named "sq_no", rather it should be "result"
print("the sq of{} is{}".format(enter_no,sq_no)) 👈#No instructions, to create this line of code at all

There are two parts of the challenge, the first part is done, as, for the second part, the challenge requires three things from you:

1) create a variable named result.

2) call the function square and in it, pass it the argument 3

3) assign this function to the variable result

If you're having trouble, msg me under this post.