REV 3 - Q WITH ANS__ Dict Function Exception 30.08.24 (1)
REV 3 - Q WITH ANS__ Dict Function Exception 30.08.24 (1)
REV 3 - Q WITH ANS__ Dict Function Exception 30.08.24 (1)
General Instructions:
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
B) Write a statement in Python to declare a dictionary whose keys are 1,2,3 and values are Apple,
Mango and Banana respectively.
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
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)
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
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
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))
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.
ANS : Python Is
Great
Python is
funny
student("John")
student('George','Jose','Seventh')
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"}