Python Python Basics Functions and Looping Create a Function

rakesh bhaskar
rakesh bhaskar
1,746 Points

eoferrror

same program when is run in workspace i got no error and result too

squaring.py
def square(a):
    b=a*a
    return b
number= int(input("enter an integer"))
sq=square(number)
print("the square of {} is {}".format(number,sq))

i am pretty new to coding but seems like u missing a space between the number = int and sq = square not sure tho :p

2 Answers

Steven Parker
Steven Parker
203,722 Points

There's no error when running this alone, but it doesn't meet the challenge criteria. In particular, the challenge instructions say "should define a single parameter named number", but the argument of this function is named "a" instead.

Then for task 2, the instructions say "call your new function and pass it the argument  3 ", but this code is requesting input from the console instead.

The instructions also say "create a new variable named result to store the value", but this code is storing it in a variable named "sq" instead.

Finally, the instructions don't require you to "print" anything.

Jason Anders
MOD
Jason Anders
Treehouse Moderator 145,089 Points

Hi rakesh bhaskar

Challenges are very specific with the instructions. For the second task, you are not asked to create any input or to print anything to the console. All that code should be deleted and only the code being asked for should be entered.

The second task simply wants a function call stored to a specific variable. So, you'll need to go back to the instructions and only code what you need for the task.

In regards to Shahar's comment, spacing doesn't normally have an effect on the code compiling, but proper practices with spacing is important when coding for readability and consensus throughout the community. A great reference is the PEP 8 Style Guide for Python

Keep Coding! :) :dizzy: