Module: (Python) Subroutines: Procedures and Functions - 1


Problem

2/11

Parameters and Arguments

Theory Click to read/hide

Parameters and Arguments

Now let's imagine that we need to display different messages in response to a user's error, depending on what kind of mistake he made.
In this case, you can write your own procedure for each error:  
def printErrorZero():
    print("Error. Division by zero!")
def printErrorInput():
    print("Error in input!")

What if there are many more possible errors? This solution will not suit us!
We need to learn how to control the procedure by telling it what error message to display.
To do this, we need parameters that we will write in parentheses after the procedure name
def printError(s):
    print("s")

In this procedure, s is a parameter - a special variable that allows you to control the procedure.
 
The parameter is a variable that determines how the subroutine works. Parameter names are comma-separated in the subroutine header.


Now, when calling the procedure, you need to indicate in brackets the actual value that will be assigned to the parameter (variable s) inside our procedure
printError("Error! Division by zero!")

Such a value is called an argument.
 
The argument is the parameter value that is passed to the subroutine when it is called.

An argument can be not only a constant value, but also a variable or an arithmetic expression.

Problem

In the program, you need to add procedure calls in such a way that when you enter the value 0, the error "Error: division by zero!"
is displayed on the screen And when entering an even number, the error "Error in input!"
Your job is to make the correct call to the procedure.