0% found this document useful (0 votes)
129 views1 page

Python Function Calls and Outputs Guide

The document contains multiple code snippets demonstrating function definitions and calls in Python. It highlights which lines of code will not execute and discusses the output of specific functions. Additionally, it evaluates the validity of certain function calls with default parameters.

Uploaded by

sijajoseph
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
129 views1 page

Python Function Calls and Outputs Guide

The document contains multiple code snippets demonstrating function definitions and calls in Python. It highlights which lines of code will not execute and discusses the output of specific functions. Additionally, it evaluates the validity of certain function calls with default parameters.

Uploaded by

sijajoseph
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Write statement to call the function: Write statement to call the function:

def Add(): def Add():


X = 10 + 20 X = 10 + 20
print(X) print(X)
_________ #statement to call the above function _________ #statement to call the above function
def Add(X,Y): def Add(X,Y):
Z = X+Y Z = X+Y
return Z return Z
_________ #statement to call the above function _________ #statement to call the above function
print(“Total =”,C) print(“Total =”,C)

Which Line Number Code will never execute? Which Line Number Code will never execute?
Write output: Write output:
def Check(num): #Line 1 def Check(num): #Line 1
if num%2==0: #Line 2 if num%2==0: #Line 2
print("Hello") #Line 3 print("Hello") #Line 3
return True #Line 4 return True #Line 4
print("Bye") #Line 5 print("Bye") #Line 5
else: #Line 6 else: #Line 6
return False #Line 7 return False #Line 7
C = Check(20) C = Check(20)
print(C) print(C)

What will be the output of following code? What will be the output of following code?
def Cube(n): def Cube(n):
print(n*n*n) print(n*n*n)
Cube(10) Cube(10)
print(Cube(10)) print(Cube(10))
def Alter(x, y = 10, z=20): def Alter(x, y = 10, z=20):
sum=x+y+z sum=x+y+z
print(sum) print(sum)
Alter(10,20,30) Alter(10,20,30)
Alter(20,y=30) Alter(20,y=30)
Alter(100,z=56) Alter(100,z=56)
def Calculate(A,B,C): def Calculate(A,B,C):
return A*2, B*2, C*2 return A*2, B*2, C*2
val = Calculate(10,12,14) val = Calculate(10,12,14)
print(type(val)) print(type(val))
print(val) print(val)
Valid/invalid: Valid/invalid:
def CalculateInterest(Principal,Rate=.06,Time): def CalculateInterest(Principal,Rate=.06,Time):
def CalculateInterest(Principal,Rate=.06,Time=2): def CalculateInterest(Principal,Rate=.06,Time=2):
#statement2 #statement2
CalculateInterest(1000,T=5) CalculateInterest(1000,T=5)
#function call for statement 2 #function call for statement 2
CalculateInterest(1000,Principal=5000,Time=4) CalculateInterest(1000,Principal=5000,Time=4)
#function call for statement 2 #function call for statement 2
CalculateInterest(Principal=5000,Rate,Time=4) CalculateInterest(Principal=5000,Rate,Time=4)
#function call for statement 2 #function call for statement 2

You might also like