CBSE Class 12 - Python (Functions & Scope)
Q2. Rewrite the program after finding the error(s):
def exceMain():
x = int(input("Enter a number:"))
if abs(x) == x:
print("You entered a positive number")
else:
x *= -1
print("Number made positive:", x)
exceMain()
Q3. Fill in the blanks and output:
def fun(x, y): # Statement-1
global a # Statement-2
x, y = y, x # Statement-3
print(a, b, x, y) # Statement-4
a, b, x, y = 1, 2, 3, 4
return [50, 100] # Statement-5
a = 10
b = 20
x = 30
c = 30
fun(1, 2)
print(a, b, x, y) # Statement-6
# Statement-4 Output: 10 20 2 1
Q4. Output of the following code:
CBSE Class 12 - Python (Functions & Scope)
def func(a, b=5, c=10):
print('a is', a, 'b is', b, 'and c is', c)
func(3, 7)
# Output: a is 3 b is 7 and c is 10
func(25, c=24)
# Output: a is 25 b is 5 and c is 24
func(c=50, a=100)
# Output: a is 100 b is 5 and c is 50