Python Quiz (Programming )– 4th Week Quiz Solution

2
3364
Python Quiz (Programming )– 4rd Week Quiz Solution
Python Quiz (Programming )– 4rd Week Quiz Solution

Disclaimer for ReGyan

If you require any more information or you have any problem regarding Copyright or have any questions about our site’s disclaimer, please feel free to contact us by email at hello@regyan.com.

 


Disclaimers for ReGyan

All the information on this website is published in good faith and for general information and educational purpose only. ReGyan does not make any warranties about the completeness, reliability, and accuracy of this information. Any action you take upon the information you find on this website (regyan.com), is strictly at your own risk. will not be liable for any losses and/or damages in connection with the use of our website.

 


Python Programming 4rd Week Quiz Solution

[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

Also See: Python Programming Quiz – 3rd Week Quiz Solution

[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

That’s all for the Python Programming Quiz – 4rd Week Quiz Solution. if you have any questions, please comment down below, we will try to answer within the first 24 hours. Hope you liked this content, We will come with another week’s quiz, Thanks for reading.

2 COMMENTS

LEAVE A REPLY

Please enter your comment!
Please enter your name here