REV 3 - Q WITH ANS__ Dict Function Exception 30.08.24 (1)

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 8

Pushpathur, Palani – 624 618

Class: XII Session: 2023-24


Computer Science (083) – Revision Test 03
Maximum Marks: 70 Time Allowed: 3
Hrs

General Instructions:

1.This question paper contains five sections, Section A to E.


2. All questions are compulsory.
3. Section A have 18 questions carrying 01 mark each.
4. Section B has 07 Very Short Answer type questions carrying 02 marks each.
5. Section C has 05 Short Answer type questions carrying 03 marks each.
6. Section D has 03 Long Answer type questions carrying 05 marks each.
7. Section E has 02 questions carrying 04 marks each.
8.All programming questions are to be answered using Python Language only.

SECTION A [ 18 X 1 = 18 Marks ]
1. A) Whis one of theese is a dictionary? 1
a) x = ('apple', 'banana', 'cherry')
b) x = {'type' : 'fruit', 'name' : 'banana'}
c) x = ['apple', 'banana', 'cherry']
B) Dictionary items cannot be removed after the dictionary has been created.
a) True b) False
2. A) A dictionary cannot have two keys with the same name. 1
a) True b) False
B) You can access dictionary items by referring to the key name.
a) True b) False
3. A) Use the get method to print the value of the "model" key of the car dictionary 1
car = { "brand": "Ford", "model": "Mustang", "year": 1964}
print(car.get("model"))
B) Consider the following code:
x = {'type' : 'fruit', 'name' : 'banana'}
print(x['type'] What will be the printed result?
a) banana b) fruit c) type = 'fruit'
4. A) Consider the following code: 1
x = {'type' : 'fruit', 'name' : 'banana'}
What is a correct syntax for changing the type from fruit to berry?
a) x{'type'} = 'berry' b) x['type'] = 'berry' c) x.get('type') = 'berry
B) Change the "year" value from 1964 to 2020 in the following
car ={ "brand": "Ford", "model": "Mustang", "year": 1964}
car["year"] = 2020
5. A) Consider the following code: 1

x = {'type' : 'fruit', 'name' : 'banana'}


A) What is a correct syntax for changing the name from banana to apple?

a) x.update({'name': 'apple'}) b) x.update('name' = 'apple') c) x.update('name','apple')

B) Write a statement in Python to declare a dictionary whose keys are 1,2,3 and values are Apple,
Mango and Banana respectively.

Ans : Dict={1:’Apple’, 2: ’Mango’,3 : ‘Banana’}


6. A) Which of the following is a valid function name? 1
a) Start_game() b) start game() c) start - game() d) All of the above

B) If the return statement is not used in the function then which type of value will be
returned by the function?
a)int b) str c) float d) None
7. A) What is the minimum and maximum value of c in the following code snippet? 1
import random
a=random.randint(3,5)
b=random.randint(2,3)
c=a+b
print(c)
a) 3 , 5 b) 5, 8 c) 2, 3 d) 3, 3
B) pow( ) function belongs to which library ?
a) math b) string c) random d) maths
8. A) What data type is the object below? 1
L = (1, 23, ‘hello’,1)
a) list b) dictionary c) array d) tuple
B) What is returned by int(math.pow(3, 2))?
a) 6 b) 9 c) error, third argument required d) error, too many arguments

9. A) Which of the following is not a type conversion functions? 1


a) int() b) str() c) input() d) float()

B ) Identify the module to which the following function load () belong to?
a) math b) random c) pickle d) sys
10 A) How many argument(s) a function can receive 1
a) Only one b) 0 or many c) Only more than one d) At least one

B)

Ans :a)
A) Value returning functions should be generally called from inside of an expression 1
11 a) True b) False
B) The variable declared inside the function is called a variable
a ) global b) local c) external d) none of the above

12 A)These are predefined functions that are always available for use. For using them we 1
don’t need to import any module
a) built in function b) pre-defined function
c) user defined function d) none of the above
B) The of a variable is the area of the program where it may be referenced
a) external b) global c) scope d) local

13 A)If you want to communicate between functions i.e. calling and called statement, 1
then you should use
a) values b) return c) arguments d) none of the above
B) Which of the following function header is correct?
a) def mul(a=2, b=5,c) b) def mul(a=2, b, c=5)
c) def mul(a, b=2, c=5) d) def mul(a=2, b, c=5)

14 A)A ________________can be skipped in the function call statements 1


a)named parameter b) default parameter c) keyword parameters d) all of the above
B)

Ans : a
15 A)The process of creating an exception object and handing it over to the runtime system is 1
called …………. an exception
a) Growing b) Throwing c) Executing d) Handling
B) The syntax of raise statement is:
a)raise exception-name ((optional argument))
b) raise exception-name {(optional argument)}
c) raise exception-name [(optional argument)]
d) None of the above
16 A) The statements inside the finally block are always executed regardless of whether an 1
exception occurred in the try block or not.
a) True b) False c) Depend on code d) None of the above
B) An exception is caught in the …….. block and handles in ……….. block
a) except, try b) try, except c) EOF, Error d) program, compile

17 A)Syntax errors are also handled as exceptions 1


a) False b) True c) Some times d) None of the above
B) An exception is a Python object that represents an ………….
a) Logic b) Expression c) Error d) Module

18 A)What keeps track of the exact position where the error has occurred. 1
a) Compiler b) Interpreter c) Both a and b d) None of the above

B) Exception handling can be done for:


a) user-defined b) built-in c) Both a and b d) None

SECTION – B [ 7 X 2 = 14 Marks ]
19. Define Dictionary and explain with example 2
20 Write a function SUMNOS() that accept a list L of numbers and find 2
sum of all even numbers and sum of all odd numbers.
If L=[1,2,3,4],
Output :
sum of even nos:6
Sum of odd numbers:4

Ans :
def SUMNOS(L): SE=0
SO=0
for i in L:
if i%2==0:
SE+=i
else:
SO+=i
print(“Sum of Even no:s=”,SE)
print(“Sum of Odd no:s=”,SO)

L=[12,34,56,45,67]
21 Define Function and list its types 2
22 A) Write output for the following code. 2
def encrypt(str):
str1="" for i in
str:
if i.isupper(): str1+=i.lower()
else:
str1+="*"
return str1
s=encrypt("HeLLo") print(s)
B) Go through the python code shown below and find out the
possible output(s) from the suggested options i to iv. Also
specify maximum and minimum value that can be assigned to
the variable j.
import random
i=random.random()
j=random.randint(0,6)
print(int(i),”:”,j+int(i))

(i)0:0 (ii)0:6 (iii)1:7 (iv)1:6

Ans :
h*ll* OR
minimum-0 maximum -1 options(i) and (ii)
23 Define Exception and list any 3 built in exceptions 2
24 Write the full syntax of try… finally with example 2
25 . list any 4 dictionary methods and explain with examples 2
SECTION – C [ 5 X 3 = 15 Marks ]
26 A) Assertion (A):- If the arguments in function call statement 3
match the number and order of arguments as defined in the
function definition, such arguments are called positional
arguments.

Reasoning (R):- During a function call, the argument list first


contains default argument(s) followed by positional argument(s).
Mark the correct choice as
(a) Both A and R are true and R is the correct explanation for A
(b) Both A and R are true and R is not the correct explanation for A
(c) A is True but R is False
d) A is false but R is True

B) Assertion (A):- If the arguments in function call statement


match the number and order of arguments as defined in the
function definition, such arguments are called positional
arguments.

Reasoning (R):- During a function call, the argument list first


contains default argument(s) followed by positional
argument(s).
Mark the correct choice as
(a) Both A and R are true and R is the correct explanation for
A
(b) Both A and R are true and R is not the correct explanation for A
(c) A is True but R is False
(d) A is false but R is True
C) Write a statement in Python to declare a dictionary whose
keys are Sub1, Sub2, Sub3 and values are Physics, Chemistry,
Math respectively
Ans : {“Sub1” : “Physics” , “Sub2” : “Chemistry” , “Sub3”:
“Math”}
27 Differentiate between positional parameter and default parameter with suitable examples 3
28 A) 3
(2 + 1)

B ) what is the use of get() in dictionary ?


29 3
30 What are the 2 ways of statements , the Programmers can forcefully 3
raise exceptions in a program.Give with suitable syntax and example
SECTION – D [ 3 X 5 = 15 Marks ]
31 A)Write the output of the code given below 5 (3+2)
def f():
global s
s += ' Is Great'
print(s)
s = "Python is funny"
s = "Python"
f()
print(s)

ANS : Python Is
Great
Python is
funny

B )Predict the output of the following


def student(firstname, lastname ='Mark', standard ='Fifth'):
print(firstname, lastname, 'studies in', standard, 'Standard')

student("John")
student('George','Jose','Seventh')

ANS :John Mark studies in Fifth


Standard
George Jose studies in Seventh Standard

32 Define Scope , Explain and differentiate the two types of scope in variable 5
33 What is the use of return statement in python . list all the return types in function with 5
example
SECTION – E [ 2 X 4 = 8 Marks ]
34 Consider the following dictionary stateCapital: 4
stateCapital = {"AndhraPradesh":"Hyderabad", "Bihar":"Patna","Maharashtra":"Mumbai",
"Rajasthan":"Jaipur"}

Find the output of the following statements:


i. print(stateCapital.get("Bihar"))
ii. print(stateCapital.keys())
iii. print(stateCapital.values())
iv. print(stateCapital.items())
v. print(len(stateCapital))
vi print("Maharashtra" in stateCapital)
vii. print(stateCapital.get("Assam"))
viii. del stateCapital["Andhra Pradesh"]
print(stateCapital)
35 Define the following 4
Ans:

You might also like