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

Martin Kolejak
Martin Kolejak
279 Points

I don't understand why my code still doesn't work on a website because on a launch workspace it works.

This is my code.

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

number_for_square = int(input("Write a number for square ")) result = square(number_for_square) print("The square of {} is {}.".format(number_for_square, result))

And this is a mistake.

.

Ran 1 test in 0.001s

OK

E

ERROR: test_results (main.TestFunctionDefinitionExecution)

Traceback (most recent call last): File "", line 48, in test_results File "/workdir/utils/challenge.py", line 20, in execute_source exec(src) File "", line 4, in EOFError: EOF when reading a line


Ran 1 test in 0.001s

FAILED (errors=1)

squaring.py
def square(number):
    return(number * number)

number_for_square = int(input("Write a number for square "))
result = square(number_for_square)
print("The square of {} is {}.".format(number_for_square, result))

1 Answer

Steven Parker
Steven Parker
221,107 Points

The instructions only ask you to create the function in task 1. Then, in task 2 you will call the function "and pass it the argument 3".

Your function is OK, but for the challenge you won't need to prompt, input, or print anything. And be sure to pass "3" as the argument when you call the function and assign "result".

Martin Kolejak
Martin Kolejak
279 Points

thank you very much :)