Use app×
Join Bloom Tuition
One on One Online Tuition
JEE MAIN 2025 Foundation Course
NEET 2025 Foundation Course
CLASS 12 FOUNDATION COURSE
CLASS 10 FOUNDATION COURSE
CLASS 9 FOUNDATION COURSE
CLASS 8 FOUNDATION COURSE
0 votes
9.4k views
in Computer by (15.7k points)
edited by

Consider the following code and answer the questions that follow: 

Book={1:'Thriller', 2:'Mystery', 3:'Crime', 4:'Children Stories'} 

Library ={'5':'Madras Diaries','6':'Malgudi Days'} 

i. Ramesh needs to change the title in the dictionary book from ‘Crime’ to ‘Crime Thriller’. He has written the following command: 

Book[‘Crime’]=’Crime Thriller’ 

But he is not getting the answer. Help him choose the correct command: 

a. Book[2]=’Crime Thriller’ 

b. Book[3]=’Crime Thriller’ 

c. Book[2]=(’Crime Thriller’) 

d. Book[3] =(‘Crime Thriller’) 

ii. The command to merge the dictionary Book with Library the command would be: 

a. d=Book+Library 

b. print(Book+Library) 

c. Book.update(Library) 

d. Library.update(Book) 

iii. What will be the output of the following line of code: print(list(Library)) 

a. [‘5’,’Madras Diaries’,’6’,’Malgudi Days’] 

b. (‘5’,’Madras Diaries’,’6’,’Malgudi Days’) 

c. [’Madras Diaries’,’Malgudi Days’] 

d. [‘5’,’6’] 

iv. In order to check whether the key 2 is present in the dictionary Book, Ramesh uses the following command: 2 in Book 

He gets the answer ‘True’. Now to check whether the name ‘Madras Diaries’ exists in the dictionary Library, he uses the following command: 

‘Madras Diaries’ in Library 

But he gets the answer as ‘False’. Select the correct reason for this: 

a. We cannot use the in function with values. It can be used with keys only. 

b. We must use the function Library.values() along with the in operator 

c. We can use the Library.items() function instead of the in operator 

d. Both b and c above are correct.

v. With reference to the above declared dictionaries, predict the output of the following code fragments

Code 1 Code 2
Library = Book Library = Book. Copy (1)
Library. pop (2) Library. Pop (2)
Print (Library) Print (Library)
Print (Book) Print (Book)

a) 

Code 1  Code 2
{1: 'Thriller', 2: 'Mystery', 3: 'Crime', 4: 'Children Stories'} {1: 'Thriller', 3: 'Crime', 4: 'Children Stories'}
{1: 'Thriller', 2: 'Mystery', 3: 'Crime', 4: 'Children Stories'} {1: 'Thriller', 3: 'Crime', 4: 'Children Stories'}


b.

Code 1 Code 2
{2:’Mystery’} {1: 'Thriller', 3: 'Crime', 4: 'Children Stories'}
{1: 'Thriller', 2: 'Mystery', 3: 'Crime', 4: 'Children Stories'} {1: 'Thriller', 3: 'Crime', 4: 'Children Stories'}

c) 

Code 1 Code 2
{1: 'Thriller', 3: 'Crime', 4: 'Children Stories'} {1: 'Thriller', 3: 'Crime', 4: 'Children Stories'}
{1: 'Thriller', 2: 'Mystery', 3: 'Crime', 4: 'Children Stories'} {1: 'Thriller', 3: 'Crime', 4: 'Children Stories'}

d) 

Code 1 Code 2
{1: 'Thriller', 3: 'Crime', 4: 'Children Stories'} {1: 'Thriller', 3: 'Crime', 4: 'Children Stories'}
{1: 'Thriller', 2: 'Mystery', 3: 'Crime', 4: 'Children Stories'} {1: 'Thriller', 2: 'Mystery', 3: 'Crime', 4: 'Children Stories'}

Please log in or register to answer this question.

1 Answer

+1 vote
by (15.2k points)

i. Correct Answer: b

ii. Correct Answer: d

iii. Correct Answer: d

iv. Correct Answer: b

v. Correct Answer: c

Welcome to Sarthaks eConnect: A unique platform where students can interact with teachers/experts/students to get solutions to their queries. Students (upto class 10+2) preparing for All Government Exams, CBSE Board Exam, ICSE Board Exam, State Board Exam, JEE (Mains+Advance) and NEET can ask questions from any subject and get quick answers by subject teachers/ experts/mentors/students.

Categories

...