Want to make creations as awesome as this one?

Transcript

Following def is the function name. The rules for function names are the same as for variable names

Following def is the function name. The rules for function names are the same as for variable names

The main body of the function can contain any Python code, including aithmetic operations and the creation of new variables. Commonly, it will use the parameters of the function to perform some kind of calculation.

The word def tells Python we’re about to start defining a function

Following the function name is a set of parentheses. These may contain a series of one or more variable names. These are the parameters of the function and will receive values each time the function is called. Parameters in the list are separated by commas. A function may have no parameters and, in this case, the set of parentheses would be empty.

The colon at the end of the line tells Python we’re ready to start defining the code that will be run when the function is called. This code is indented to indicate which code is part of the function and which code follows it

If the execution of the code reaches the word return, if there is an expression which follows it, it will be evaluated and its value will be returned. If there is no expression after it, the special value None will be returned to indicate the lack of a value.

Lines of code after a return statement will never be executed as the return will cause the function to finish executing. As a result, you would not normally include code after a return statement.

Following def is the function name. The rules for function names are the same as for variable names

Following def is the function name. The rules for function names are the same as for variable names

The main body of the function can contain any Python code, including aithmetic operations and the creation of new variables. Commonly, it will use the parameters of the function to perform some kind of calculation.

The word def tells Python we’re about to start defining a function

Following the function name is a set of parentheses. These may contain a series of one or more variable names. These are the parameters of the function and will receive values each time the function is called. Parameters in the list are separated by commas. A function may have no parameters and, in this case, the set of parentheses would be empty.

The colon at the end of the line tells Python we’re ready to start defining the code that will be run when the function is called. This code is indented to indicate which code is part of the function and which code follows it

If the execution of the code reaches the word return, if there is an expression which follows it, it will be evaluated and its value will be returned. If there is no expression after it, the special value None will be returned to indicate the lack of a value.

Lines of code after a return statement will never be executed as the return will cause the function to finish executing. As a result, you would not normally include code after a return statement.

Following def is the function name. The rules for function names are the same as for variable names

Following def is the function name. The rules for function names are the same as for variable names

The main body of the function can contain any Python code, including aithmetic operations and the creation of new variables. Commonly, it will use the parameters of the function to perform some kind of calculation.

The word def tells Python we’re about to start defining a function

Following the function name is a set of parentheses. These may contain a series of one or more variable names. These are the parameters of the function and will receive values each time the function is called. Parameters in the list are separated by commas. A function may have no parameters and, in this case, the set of parentheses would be empty.

The colon at the end of the line tells Python we’re ready to start defining the code that will be run when the function is called. This code is indented to indicate which code is part of the function and which code follows it

If the execution of the code reaches the word return, if there is an expression which follows it, it will be evaluated and its value will be returned. If there is no expression after it, the special value None will be returned to indicate the lack of a value.

Lines of code after a return statement will never be executed as the return will cause the function to finish executing. As a result, you would not normally include code after a return statement.

def

quadratic

( )

:

quad_term = a * x ** 2lin_term = b * x

return

quad_term + lin_term + c

print

(quad_term)

print ("Next")

a, b, c, x

The word def tells Python we’re about to start defining a function

Following def is the function name. The rules for function names are the same as for variable names

If the execution of the code reaches the word return, if there is an expression which follows it, it will be evaluated and its value will be returned. If there is no expression after it, the special value None will be returned to indicate the lack of a value.

Lines of code after a return statement will never be executed as the return will cause the function to finish executing. As a result, you would not normally include code after a return statement.

The main body of the function can contain any Python code, including arithmetic operations and the creation of new variables. Commonly, it will use the parameters of the function to perform some kind of calculation.

Following the function name is a set of parentheses. These may contain a series of one or more variable names. These are the parameters of the function and will receive values each time the function is called. Parameters in the list are separated by commas. A function may have no parameters and, in this case, the set of parentheses would be empty.

If the execution of the code reaches the word return, if there is an expression which follows it, it will be evaluated and its value will be returned. If there is no expression after it, the special value None will be returned to indicate the lack of a value.

Lines of code after a return statement will never be executed as the return will cause the function to finish executing. As a result, you would not normally include code after a return statement.

The colon at the end of the line tells Python we’re ready to start defining the code that will be run when the function is called. This code is indented to indicate which code is part of the function and which code follows it.

def

cube_surface_area

(side_length)

:

6 * face_area

face_area = side_length ** 2

area = cube_surface_area (3)

return

def

cube_surface_area

(side_length)

:

6 * face_area

face_area = side_length ** 2

area = cube_surface_area (3)

return

;

result

define

side_length

def cube_surface_area(side_length): face_area = side_length ** 2 return 6 * face_area area = cube_surface_area(3)

Did you get it right?

Compare your code

Practice the composition of functions:

def

cube_surface_area

(side_length)

:

6 * face_area

face_area = side_length ** 2

area = cube_surface_area (3)

return

;

result

define

side_length

Compare your code

Thank you for your submission.

Focus on Definitions: StatementA Python statement is a piece of code which is complete and can be run or “executed” by the Python interpreter (the program on your computer which runs the Python code). Normally, and everywhere in this course, there will be one statement per line of code. The code of a statement tells the computer to do something. In the cases above, each statement calls the print function. For now, statements will be executed one after another, from top to bottom.

Lorem ipsum dolor

Did you get it right?