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

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
8,669 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.