Python Python Basics Functions and Looping Create a Function

Peris Kwamboka
Peris Kwamboka
412 Points

I can't seem to trace what the error is

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

calc = int(input("Enter a number  "))
result = square(calc)
print("The square is{}".format(result))

2 Answers

joelearner
joelearner
35,815 Points

Hi Peris,

The idea for the first part of the challenge is to square the value, meaning multiply the value by itself. Multiplying by the same value is not the same as multiplying by 2. You want to write something like number * number for the return statement.

Then you're asked to call the function that you created in the first step and supply a value for the argument. Then you can assign it to a variable called result. So you should have something that looks like: result = square(3)

Does this help?

Cheers!

Steven Parker
Steven Parker
153,097 Points

A "square" isn't a number times 2. It's either a number times itself (number * number), or a number raised to the power of 2 (number**2).

You may also want to add a space between the word "is" and the placeholder for the result.

Peris Kwamboka
Peris Kwamboka
412 Points

I have made the changes but not working still. Not sure what the issue is

Steven Parker
Steven Parker
153,097 Points

You'll get best results from the challenges by doing only what the instructions ask for. In task 1, you need only define the function that returns the square. Don't add any other code.

Then in task 2, the instructions say "Under the function definition, call your new function and pass it the argument 3." So you'll add a variable assignment calling your function. You won't need to input or print anything, or create any variables other than "result".