1.

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 fragmentsCode 1Code 2Library = BookLibrary = 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 1Code 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 1Code 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 1Code 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'}

Answer»

i. Correct Answer: b

ii. Correct Answer: d

iii. Correct Answer: d

iv. Correct Answer: b

v. Correct Answer: c



Discussion

No Comment Found

Related InterviewSolutions