Programming DAaa

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

Unit 2 Discussion Assignment

Example 1: Define a function that takes an argument. Call the function. Identify what code is the

argument and what code is the parameter.

Argument 1 is ('Shahla is 24 years old')


Argument 2 is ('Shahla is a student is UoPeople, studying business administration')
Argument 3 is ('Shahla lives in Saudi Arabia')
Argument 4 is (999 - 99 ** 9 / 9)
The parameter is (Shahla), and all the arguments are assigned to this parameter.

Example 2: Call your function from Example 1 three times with different kinds of arguments: a

value, a variable, and an expression. Identify which kind of argument is which.


The variables are x and y, which have the values 999 for x, and 99 for y. The expression here is

the function x-y.

Example 3: Construct a function with a local variable. Show what happens when you try to use

that variable outside the function. Explain the results.

the error message shows that (local variables) is not defined, while it is a local variable of the

function (new function).

Example 4: Construct a function that takes an argument. Give the function parameter a unique

name. Show what happens when you try to use that parameter name outside the function.

Explain the results.

The output here is clear, unlike what happened in the previous example. When I made a

parameter and defined what is the value of xxx, the result would show off if I used that

parameter name outside the function.


Example 5: Show what happens when a variable defined outside a function has the same name

as a local variable inside a function. Explain what happens to the value of each variable as the

program runs.

Whenever the values changes, whether the inner one or the outer, they won’t effect each other’s.

For example, if the inner one changes, the outer one won’t be effects, and vice versa.

You might also like