Python Python Basics Functions and Looping Create a Function

Tsholofelo Goabaone Kenathetswe
Tsholofelo Goabaone Kenathetswe
2,469 Points

please am frustrated by the challenge to create function, am failing over and over, kindly assist!

Create a function named square...
def split_check(square):
    return square*2

3 Answers

Maxwell Newberry
Maxwell Newberry
Front End Web Development Techdegree Student 7,675 Points

In your return statement you are simply multiplying the argument by 2, when the challenge is asking for you to square the number. Meaning, multiply the passed argument by itself, not by 2.

def square(number):
    return  number * number

Don't be frustrated! It takes time and you're definitely on the right track. :)

Owen Bell
Owen Bell
8,052 Points

To add to this, you can define the index that you should raise your base to (i.e. how many times you should be multiplying the parameter by itself) with a double-asterisk:

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

Which is only slightly more streamlined in this particular case, but is much more useful for running higher-order calculations or functions where the index should be an argument to be provided or where it varies over time.

David Garcia
David Garcia
Python Web Development Techdegree Student 3,384 Points

Tip: read the questions very carefully they tell you how to do said problem but you must come up with the logic...

1: first you need to create a defined function called 'square' that takes an argument called 'number' example: def example(argument):

2: then create the value of said argument called number inside defined function and tell it what it means example: def example(argument): argument = argument * argument

3: then return said value as soo....:

def example(argument): argument = argument * argument return argument

if you don't understand this, here's the answer. I'd advise you to look at the answer and study from it and remember what it does also remember there's different ways of doing problems.

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

Rutendo Chaurura
Rutendo Chaurura
6,362 Points

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