Worksheet1 Function Ans
Worksheet1 Function Ans
def Add():
X = 10 + 20
print(X)
Add() _________ #statement to call the above function
def Add(X,Y):
Z = X+Y
return Z
_________ #statement to call the above function
print(“Total =”,C)
C = Add(10,20) # Parameter value is user dependent
Which Line Number Code will never execute?
Write output:
def Check(num): #Line 1
if num%2==0: #Line 2
print("Hello") #Line 3
return True #Line 4
print("Bye") #Line 5
else: #Line 6
return False #Line 7
C = Check(20)
print(C)
Line 5
Hello
True
What will be the output of following code?
def Cube(n):
print(n*n*n)
Cube(10)
print(Cube(10))
1000
1000
None
def Alter(x, y = 10, z=20):
sum=x+y+z
print(sum)
Alter(10,20,30)
Alter(20,y=30)
Alter(100,z=56)
60
70
166
def Calculate(A,B,C):
return A*2, B*2, C*2
val = Calculate(10,12,14)
print(type(val))
print(val)
<class 'tuple'>
(20, 24, 28)
Valid/invalid:
def CalculateInterest(Principal,Rate=.06,Time):#statement1 SyntaxError: non-default argument follows
default argument
def CalculateInterest(Principal,Rate=.06,Time=2): #statement2#valid
CalculateInterest(1000,T=5) #function call for statement 2
# TypeError: CalculateInterest() got an unexpected keyword argument 'T'
CalculateInterest(1000,Principal=5000,Time=4) #function call for statement 2
TypeError: CalculateInterest() got multiple values for argument ‘Principal'
CalculateInterest(Principal=5000,Rate,Time=4) #function call for statement 2
SyntaxError: positional argument follows keyword argument