Problem Solving And Python Programming Set 15
On This Page
This set of Problem Solving and Python Programming Multiple Choice Questions & Answers (MCQs) focuses on Problem Solving And Python Programming Set 15
Q1 | Suppose d = {“john”:40, “peter”:45}, to delete the entry for “john” what command do we use?
- d.delete(“john”:40)
- d.delete(“john”)
- del d[“john”]
- del d(“john”:40)
Q2 | Suppose d = {“john”:40, “peter”:45}. To obtain the number of entries in dictionary which command do we use?
- d.size()
- len(d)
- size(d)
- d.len()
Q3 | print(list(d.keys()))
- [“john”, “peter”]
- [“john”:40, “peter”:45]
- (“john”, “peter”)
- (“john”:40, “peter”:45)
Q4 | Which of these about a dictionary is false?
- the values of a dictionary can be accessed using keys
- the keys of a dictionary can be accessed using values
- dictionaries aren’t ordered
- dictionaries are mutable
Q5 | Which of the following is not a declaration of the dictionary?
- {1: ‘a’, 2: ‘b’}
- dict([[1,”a”],[2,”b”]]) c) {1,”a”,2”b”}
- d) { }
Q6 | ,4))
- 1
- a
- 4
- invalid syntax for get method
Q7 | ,4))
- error, invalid syntax
- a
- 5
- 4
Q8 | ))
- {1: ‘a’, 2: ‘b’, 3: ‘c’}
- c
- {1: 3, 2: 3, 3: 3}
- no method called setdefault() exists for dictionary
Q9 | ,"D") print(a)
- {1: ‘a’, 2: ‘b’, 3: ‘c’, 4: ‘d’}
- none
- error
- [1,3,6,10]
Q10 | Which of the following isn’t true about dictionary keys?
- more than one key isn’t allowed
- keys must be immutable
- keys must be integers
- when duplicate keys encountered, the last assignment wins
Q11 | ) print(a)
- {1: 5}
- {1: 5, 2: 3}
- error, syntax error for pop() method d) {1: 5, 3: 4}
Q12 | ,9))
- 9
- 3
- too many arguments for pop() method
- 4
Q13 | Which of the statements about dictionary values if false?
- more than one key can have the same value
- the values of the dictionary can be accessed as dict[key]
- values of a dictionary must be unique
- values of a dictionary can be a mixture of letters and numbers
Q14 | If a is a dictionary with some key-value pairs, what does a.popitem() do?
- removes an arbitrary element
- removes all the key-value pairs
- removes the key-value pair for the key given as an argument
- invalid method for dictionary
Q15 | )
- counter({4: 3, 2: 2, 3: 1})
- {3:1}
- {4:3}
- [(4, 3)]
Q16 | print(a)
- true
- false
Q17 | ][1])
- [2,3,4]
- 3
- 2
- an exception is thrown
Q18 | ,2,3],"check")
- syntax error
- {1:”check”,2:”check”,3:”check”}
- “check”
- {1:none,2:none,3:none}
Q19 | If b is a dictionary, what does any(b) do?
- returns true if any key of the dictionary is true
- returns false if dictionary is empty
- returns true if all keys of the dictionary are true
- method any() doesn’t exist for dictionary
Q20 | ]
- an exception is thrown since the dictionary is empty
- ‘ ‘
- 1
Q21 | ]
- 1
- 0
- an exception is thrown
- ‘ ‘
Q22 | ]
- 4
- 0
- an exception is thrown
- 7
Q23 | To open a file c:\scores.txt for reading, we use
- infile = open(“c:\\scores.txt”, “r”)
- infile = open(“c:\\scores.txt”, “r”)
- infile = open(file = “c:\\scores.txt”, “r”)
- infile = open(file = “c:\\scores.txt”, “r”)
Q24 | To open a file c:\scores.txt for writing, we use
- outfile = open(“c:\\scores.txt”, “w”)
- outfile = open(“c:\\scores.txt”, “w”)
- outfile = open(file = “c:\\scores.txt”, “w”)
- outfile = open(file = “c:\\scores.txt”, “w”)
Q25 | To open a file c:\scores.txt for appending data, we use
- outfile = open(“c:\\scores.txt”, “a”)
- outfile = open(“c:\\scores.txt”, “rw”)
- outfile = open(file = “c:\\scores.txt”, “w”)
- outfile = open(file = “c:\\scores.txt”, “w”)