Question: 1. Why is the following function not considered as a well-defined function? def area(radius): result =PI * radius * radius return result PI = 3.14

1. Why is the following function not considered as a well-defined function?

def area(radius): result =PI * radius * radius return result

PI = 3.14

result = area(10)

print(result)

2. List the variables have local scope in the following program:

def circle_area(radius):

result =3.14 * radius * radius return result

area = circle_area(10)

print(area)

3.

List the variables have global scope in the following program:

def circle_area(radius):

result =3.14 * radius * radius return result

area = circle_area(10)

print(area)

4. Consider the following Python code. Note that line numbers are included on the left. What is the order of the execution of the program? List the line number that the program is executed in order.

1. def pow(b, p): 2. y = b ** p 3. return y 4. 5. def square(x): 6. a = pow(x, 2) 7. return a 8. 9. n = 5 10. result = square(n) 11. print(result)

5. Can you use the same name for a local variable as a global variable? Is it recommended to use the same name for a local variable as a global variable?

6. A program contains the following function definition:

def cube(x): return x*x*x

Write a statement that passes 4 as an argument to the function and assigns its return value to variable result.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!