Answer Sheet - 38 Functions and Procedures
Answer Sheet - 38 Functions and Procedures
Functions and
procedures
teachcomputerscience.com
1.
Activity
teachcomputerscience.com
Activity-1
Duration: 10 minutes
teachcomputerscience.com
Activity-2
Duration: 15 minutes
def small_2(p,q):
if p<q:
return p
else:
return q
x= int(input("Enter first number: "))
y= int(input("Enter second number: "))
print ("The smallest number is: " , small_2(x,y))
def small_2(p,q):
if p<q:
return p
else:
return q
def small_3(a,b,c):
return small_2(c, small_2(a,b))
teachcomputerscience.com
2.
End of topic
questions
teachcomputerscience.com
End of topic questions
1. What are the advantages of using functions and procedures in
programs?
• The overall size of code is reduced
• improves the readability of the program
• Reduces the time taken to write and test the program.
• Reduces the time taken to debug the program.
• Use of in-built functions saves time and reduces the possibility
of errors.
2. What are functions?
Functions are subprograms that can be called whenever required
from the main program.
3. Explain the function-call process in detail.
i. The main program executes until it reaches a function call
statement.
ii. Control and inputs are passed to function.
iii. The function code is executed.
iv. Control transferred to main program.
v. Output from function returned to function call statement.
vi. The main program continues the execution of the program.
4. What parameters are included in function definition?
Name of function, inputs to be passed to the function, function
code and outputs that are produced by the function
5. How are procedures different from functions?
Procedures like functions are sub-programs called from the main
program but do not return any values. Functions always return
value(s).
teachcomputerscience.com
End of topic questions
6. Using functions or procedures, write a Python program to check
whether the given string is a palindrome or not.
def palindrome(string):
k = ""
for i in string:
k=i+k
if (string==k):
print("Yes, this string is a palindrome")
break
else:
print("Not a palindrome")
teachcomputerscience.com