Answer to Question #331446 in Python for tina

Question #331446

Example 1: Define a function that takes an argument. Call the function. Identify what code is the argument and what code is the 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. 


Example 3: Create a function with a local variable. Show what happens when you try to use that variable outside the function. Explain the results.


Example 4: Create 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.


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.

184 words

PermalinkReply

4










1
Expert's answer
2022-04-20T15:34:51-0400
def function(x): #x is param
    print(x)


Example_5 = 1
function(2**3)
function('Example 2')
function(1)


def function_2():
    loc = 555


# function_2() if you run this code,
#print(loc)  there will be an error, since the variable is local
def function_3(unical_param):
    print('really unical')


function_3(1000)


#print(unical_param) if you run this code,there will be NameError
Example_5 = 7


def function_4(Example_5):
    print(Example_5)


""" variable inside a function and a variable with the same name outside
 of it are two different variables
 and their values do not overlap or replace """
function_4(Example_5)

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS