Header Ads Widget

Responsive Advertisement

Python Programming Week 4 Quiz Solution [Python Programming course on Prutor.ai by IIT kharagpur]

Here you will get all the assignment and quiz solutions of Python Programming Course by prutor.ai. Prutor is an online smart tutoring platform which provides various MOOC courses for student and organised by by IIT Kharagpur. At the end of each course student gets a certificate for sucessfull  completion of each course but throughout the course students have to pass all the weekly assignments and quizes.

 

[1] Which of the following is the correct way to declare a dictionary in python

  •  (a): dict = {“key”:”value”}
  • (b): dict [“key”:”value”]
  • (c): Dict = {“key” – “value”}
  • (d): Dict = [“key”:”value”]

Answer: (a) dict = {“key”:”value”}

[2] We have an empty dictionary declared as dict = {}. Which of the following is correct way to add key-value pairs in it.

  • (a): dict[‘value’] = ‘key’
  • (b): dict[‘key’] = ‘value’
  • (c): dict.append(‘key’)=’value’
  • (d): None of the above

Answer: (b) dict[‘key’] = ‘value’

[3]  In python, Which is the correct way to remove an element from the dictionary

  • (a):

    d = {‘a’: ‘first’, ‘b’: ‘second’}

    del d[‘b’]

    print (d)

  • (b):

    d = {‘a’: ‘first’, ‘b’: ‘second’}

    remove d[‘b’]

    print (d)

  • (c): d = {‘a’: ‘first’, ‘b’: ‘second’}

    print (del d[‘b’])

  • (d): None of the above

Answer: (a)  d = {‘a’: ‘first’, ‘b’: ‘second’}

del d[‘b’]

print (d)

[4] In python, One can set the default value in get() function to be returned if key does not exist in dictionary

  • (a): True
  • (b): False

Answer: (a) True

[5] Which of the following function is used to get all the keys in a dictionary in python

  • (a): getkeys()
  • (b): get_keys()
  • (c): keys()
  • (d): keysvalue()




Answer: (c) keys()

[6]  Can we can add a dictionary to a list and similarly add a list to a dictionary

  • (a): True
  • (b): False

Answer: (a) True

[7]  Which of the following is false for dictionaries

  • (a):Unordered set of key, value pair
  • (b): ordered set of key, value pair
  • (c): Keys are always unique
  • (d): None of the above

Answer: (b) ordered set of key, value pair


[8] Which of the following is used to iterate over keys in dictionaries

  • (a): dict.keys()
  • (b): dict.get(key,value)
  • (c): for k in dict
  • (d): All of the above

Answer: (c) for k in dict

[9] Which of the following function is used to get the sorted list

  • (a): list1.sort()
  • (b): list1.sorted()
  • (c): list1.sorting()
  • (d): list1.sortlist()

Answer: (b) list1.sort()

[10] What will be the output of the following code dict = { x:x for x in range(1,3) }

  • (a): {}
  • (b): {x:x,x:x,x:x}
  • (c): {1: 1, 2: 2}
  • (d): None of the above




Answer:(c) {1: 1, 2: 2}

[11] Which of the following is true in python

  • (a): input is given using input function
  • (b): input function takes one argument
  • (c): input pauses the program to take input from user
  • (d): All of the above

Answer: (d) All of the above

[12] In python 3.x, what will be the type of age variable in the following code: age = input (“Please enter your age”)

  • (a): String
  • (b): Integer
  • (c): Whatever type is given to it
  • (d): None of the above

Answer: (a) String

[13] What will be the output of the following program

int =5
while int >=2:
print (int)
int = int -1

  • (a): 4 3 2
  • (b): 5 4 3 2
  • (c): 5 4 3
  • (d): 5 4 3 2 1

Answer:(b) 5 4 3 2

[14]  Can a break statement be used to exit a while loop?

  • (a): True
  • (b): False




Answer:(a) True

[15] What will be the output of the following program

int =3

while int >=2:

    print (int)

    int -= 1

  • (a): 3
  • (b): 2
  • (c): 3 2
  • (d): Error in code

Answer:(c) 3 2


If you have any quetions, please comment down below, we will try to answer with in first 24 hour. Hope you liked this content, We will come with another week’s quiz, Thanks for reading. Good Bye.

Post a Comment

0 Comments