[go: up one dir, main page]

0% found this document useful (0 votes)
6 views2 pages

Section A

The document contains a series of questions related to Python programming, specifically focusing on dictionaries, functions, and variable scope. It is divided into sections with varying question formats, including multiple choice, definitions, and coding predictions. The questions assess knowledge on dictionary methods, function definitions, and code output predictions.

Uploaded by

svvsuganyacbse
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)
6 views2 pages

Section A

The document contains a series of questions related to Python programming, specifically focusing on dictionaries, functions, and variable scope. It is divided into sections with varying question formats, including multiple choice, definitions, and coding predictions. The questions assess knowledge on dictionary methods, function definitions, and code output predictions.

Uploaded by

svvsuganyacbse
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
You are on page 1/ 2

Section A

Each question 1 marks

1. What does the pop() method do when used on a Python dictionary?


a) Removes and returns the last item of the dictionary
b) Removes and returns the item with the specified key
c) Removes and returns the item at the specified index
d) Removes and returns the first item of the dictionary
2. Which of the following methods is used to add a new key-value pair to a
Python dictionary?
a) add() b) insert() c) append() d) None of the
above
3. What will be the output of the following Python code snippet?
my_dict = {'a': 1, 'b': 2, 'c': 3}
result = my_dict.get('b', 0)
print(result)
a) 1 b) 2 c) 3 d) 0
4. Which of the following methods is used to get a list of all keys in a Python
dictionary?
a) keys() b) get_keys() c) list() d) None of
the above
5. Which keyword is used to define a function ?
6. What will be the output of the following code snippet?
def add(a, b):
return a + b

result = add(3, 5)
print(result)
a) 8 b) 3 + 5 c) 35 d) None
7. What is the primary purpose of a function in Python?
a) To execute a block of code repeatedly
b) To organize code into manageable units and promote code reuse
c) To perform mathematical operations
d) To define conditional statements
8. Assertion (A): In Python, a key should not be duplicated within the
dictionary.
Reason (R): While creating a dictionary, a key and its value are separated
by a colon (:) and the key: value pairs are separated by commas (.) All the
key: value pairs are enclosed within the curly braces {}.
Section B
Each question 2 marks
9. Define function?
10. List out advantages of function?
11. Differentiate global and local variable?

Section C
Each question 3 marks
12.Predict the output of the following code:
d = {"apple": 15, "banana": 7, "cherry": 9}
str1 = ""
for key in d:
str1 = str1 + str(d[key]) + "@" + “\n”
str2 = str1[:-1]
print(str2)
Section D
Each questions 4 marks
13. Consider the following dictionary Bus
Bus={‘A1 Travels’:[‘Banglore’,’Kottayam’,’Ac’,1650],
’TVK Travels’:[‘Banglore’,’Hydrabad’,’Non AC’,2350],
‘RKR Travels’:[‘Banglore’,’Trivandrum’,’Non AC’,2000],
‘KBS Travels’:[‘Banglore’,’Chennai’,’AC’,1350],
‘Mythri’:[‘Banglore’,’Hydrabad’,’AC’,2750]}
a. Display Bus name all Non AC bus.
b. Display the bus name and price of all the bus which amount is grater than
1800
c. Display the name of bus which contain more than 10 character in its name
14.A dictionary Cinema has the following structure:
{MNO:[MNAME, MTYPE]}
Where MNO – Movie Number ,MNAME – Movie Name, MTYPE is Movie Type
Write a program that accepts mtype as the movie type from user and
displays all the records from the dictionary CINEMA, that have the value of
Movie Type as mtype.
Section E
15.
a. Predict the output of the following code
D={"Saurav":80,"Aditi":89, "Aman":75}
print(min(D))
R={"Aditi":85, "Rajat":65}
R.update(D)
print(D)
P=D
P["Aman"]=82
print(D)
b. Predict the output of the following code:
D={1:"One", 2:"Two", 3:"Three",4:"Four",30:"Thirty"}
L=[]
for K,V in D. items():
if V[0]=="T":
L.append(K)
print(L[::-1]) (3+2)

You might also like