AKTU Python Programming 4th Week Quiz Solution



AKTU ICT Academy Python Programming a practical Approach 4th Week Quiz Solutions

Hey guys here are the solutions of AKTU ICT Academy Python quiz solutions for the first week. AKTU released noncredit courses for 2nd-year computer science students of B. Tech. The course code is KNC 301/KNC 302.


These answers are for all those who have confusion in the questions or they don’t want to submit wrong answers. Please attempt the quiz yourself before proceeding for the answers.

Disclaimer :- I don't claim for the 100% accuracy of the answers. I tried my level best to present the correct answers and I'm not responsible if any of the answer is incorrect.


[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: (a) Unordered 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.sorted()

[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
SHARE If you find this useful, please share with your friends and Community.
CODE TOGETHER..GROW TOGETHER.
Newer Posts Newer Posts Older Posts Older Posts

More posts

Comments

Post a Comment

Sponsored Content