[Type B] Working with Functions – Chapter 3 Sumita Arora

|
Table of Contents

6. What will be the output of the following programs?

6. (i) Python
num = 1
def myfunc():
    return num
print(num)
print(myfunc())
print(num)
Output
1
1
1
6. (ii) Python
num = 1
def myfunc():
    num = 10
    return num
print(num)
print(myfunc())
print(num)
Output
1
10
1
6. (iii) Python
num = 1
def myfunc():
    global num
    num = 10
    return num
print(num)
print(myfunc())
print(num)
Output
1
10
10
6. (iv) Python
def display():
    print("Hello", end=' ')
display()
print("there!")
Output
Hello there!
Output (i), (ii), (iii), (iv)
1
1
1
1
10
1
1
10
10
Hello there!
"Spread the light within, illuminate the hearts around you. Sharing is not just an action, but a sacred journey of connecting souls."~ Anonymous

Leave a Reply

Your email address will not be published. Required fields are marked *