0% found this document useful (0 votes)
41 views4 pages

Chapter-3 & 4 Assignment-3

This document contains an assignment on functions and modules in Python with multiple choice questions, code snippets and questions to test understanding. It includes questions on built-in functions, function definitions, parameters, scope of variables and importing modules. Students are asked to write code for problems involving functions, modules, sorting and menu driven programs.

Uploaded by

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

Chapter-3 & 4 Assignment-3

This document contains an assignment on functions and modules in Python with multiple choice questions, code snippets and questions to test understanding. It includes questions on built-in functions, function definitions, parameters, scope of variables and importing modules. Students are asked to write code for problems involving functions, modules, sorting and menu driven programs.

Uploaded by

Shagun Behera
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

TIHS/2023-24/ASSIGNMENT/Pg-1

THE INDIAN HEIGHTS SCHOOL


ASSIGNMENT -3 (2023 – 24)
COMPUTER SCIENCE – XII (083)
CHAPTER-3 & 4 (FUNCTIONS & MODULES)
Develop a passion for learning. If you do, you will never cease to grow. Anthony J. D'Angelo
Date – April 29, 2023
Multiple Choice Questions:
1. Which of the following is the use of id() function in Python?
a. Id returns the identity of the object
b. Every object doesn’t have a unique id
c. Id returns the type of function
d. Id returns the type of a variable
2. What is a variable defined outside a function referred to as?
a. A static variable c. a global variable
b. A local variable d. an auto variable
3. What is a variable defined outside a function referred to as?
a. A static variable c. a global variable
b. A local variable d. an auto variable
4. If a function doesn’t have return statement, which of the following does the function return?
a. Int b. Null c. None of these d. An exception
Find the output generated by the following code:
5. What will be the output of the following Python code?
>>>import math
a) print(math.floor(5.5))
b) print(math.pow(2,5))
c) print(math.ceil(4.3))
d) print(math.fabs(-21.5))
6. What will be the output of the following Python code?
>>>import random
a) random.random()
b) print(random.randint(4,10))
c) print(random.uniform(4,10))
d) print(random.choice((1,2,3,4,5,6)))
e) >>>list=[1,2,3,4]
>>> random.shuffle(list)
>>> print(list)
7. What will be the output of the following Python code?
a) >>>int(‘12’) e) >>>float(36)
b) >>>type(True) f) >>>max(7,1,5,0)
c) >>>abs(-56) g) >>>len(‘computer’)
d) >>>type(34/7) h) >>>type(78%5)
8. What are the possible outputs for the following code:
import random
a=[20,30,40,50,60,70]
FROM=random.randint(1,3)
TO=random.randint(2,4)
for k in range(FROM,TO+1):
print(a[k],end='#')
1) 10#40#70# 2) 30#40#50# 3) 50#60#70# 4) 40#50#70#
TIHS/2023-24/ASSIGNMENT/Pg-2

9. What will be the output of the following code?


print type (type(int))
a. type ‘int’ b. type ‘type’ c. Error d. null
10. What is the output of the function?
len ([“hello”,2,4,6])
a. 4 b. 3 c. Error d. 6
11. What will be the output of the following code?
import math
abs(math.sqrt(25))
b. 5 b. 5.0 c. Error d. no output
12. What is the output of the function?
min(max(False, -3, -4), 2, 7)
b. -3 b. -4 c. True d. False
13. Write the output of the following:
def show5():
print("hello")
show5a()
def show5a():
print("bye")
show5()
14. Write the output of the following:
def sum(count): #method to find sum
s=0
for i in range(1, count+1):
s+=1
return s
print(sum(2)) #function call
print(sum(5))
15. What are the possible output(s) of the following code:

a. 0:0 b. 1:6 c. 2:4 d. 0:3


16. Write the output of the following code:

17. Write the output of the following code:


TIHS/2023-24/ASSIGNMENT/Pg-3

18. Write the output of the following code:

Fill in the blanks:


19. ____________ function return the value of an alphabet passed to it as an argument.
20. The function pow(x,y,z) is evaluated as _________________
21. The output of the round (234,7846,2) is __________________
22. Built in functions are also known as ______________ functions.
Rewrite the following code after removing the syntax error(s). Underline each correction.
23. def add:
total=0
n=input("enter a number:"
m=input("enter another number:)
total=m+n
print total
add()
24. function f1(b):
if b>0 then:
return "positive"
else return "not positive"
m=int(input("enter a number:"))
msg=f1()
print(msg)
25. def isMultiple(a b):
if a%b=0:
return true
else return false
m=int(input("enter a number:"))
n=int(input("enter another number:"))
if isMultiple[m,n]:
print("m is a multiple of n")
else print(m, "is not a multiple of n")
26. find HCF(a, b):
h=a
while b%h!=0 OR a%h!=0
h-=1
return h
TIHS/2023-24/ASSIGNMENT/Pg-4

m=int(input("enter a number:"))
n=int(input("enter another number:"))
HCF(m,n)=h
print("HCF=" h)
Case study: Answer the following questions based on the given script/code.
def show(a):
A=10
A=A+3
Return A
B=100
Res=show(B)
27. Name the formal parameter.
a. A b. b c. a d. Res
28. Name the actual parameter.
b. A b. b c. a d. Res
29. Name a local variable(s).
a. A b. B c. a d. Res
30. Name a global variable(s).
a. A b. B c. a d. Res
31. Variable ‘a’ will return the value to variable __________________.
Answer the following questions:
32. Differentiate between formal parameters and actual parameters
33. Differentiate between local and global variables.
34. Differentiate between mutable and immutable objects
35. Write the use of following keywords: def, return, global
36. consider the following code and answer the questions written as comments in the code:

Write a Python program for the following:


37. WAP to find the sum of all elements in the list with the help of variable length argument type.
38. WAP using function to change the alternate index value of the element.
39. WAP using function insert_sort(list1, ele) to insert new element in a sorted list.
40. Write a menu driven Python program having the following user defined modules using import statements:
Addition of 2 numbers - save it as sum.py
Multiplication of 2 numbers - save it as mul.py

You might also like