Problem Solving And Python Programming Set 33
On This Page
This set of Problem Solving and Python Programming Multiple Choice Questions & Answers (MCQs) focuses on Problem Solving And Python Programming Set 33
Q1 | 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) { }
Q2 | ,4))
- 1
- a
- 4
- invalid syntax for get method
Q3 | ,4))
- error, invalid syntax
- a
- 5
- 4
Q4 | ))
- {1: ‘a’, 2: ‘b’, 3: ‘c’}
- c
- {1: 3, 2: 3, 3: 3}
- no method called setdefault() exists for dictionary
Q5 | ,"D") print(a)
- {1: ‘a’, 2: ‘b’, 3: ‘c’, 4: ‘d’}
- none
- error
- [1,3,6,10]
Q6 | 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
Q7 | ) print(a)
- {1: 5}
- {1: 5, 2: 3}
- error, syntax error for pop() method d) {1: 5, 3: 4}
Q8 | ,9))
- 9
- 3
- too many arguments for pop() method
- 4
Q9 | 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
Q10 | 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
Q11 | ] test[1] = 'D' del test[2] print(len(test))
- 0
- 2
- error as the key-value pair of 1:’a’ is already deleted
- 1
Q12 | )
- counter({4: 3, 2: 2, 3: 1})
- {3:1}
- {4:3}
- [(4, 3)]
Q13 | print(a)
- true
- false
Q14 | ][1])
- [2,3,4]
- 3
- 2
- an exception is thrown
Q15 | ,2,3],"check")
- syntax error
- {1:”check”,2:”check”,3:”check”}
- “check”
- {1:none,2:none,3:none}
Q16 | 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
Q17 | ]
- an exception is thrown since the dictionary is empty
- ‘ ‘
- 1
Q18 | ]
- 1
- 0
- an exception is thrown
- ‘ ‘
Q19 | ]
- 4
- 0
- an exception is thrown
- 7
Q20 | 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”)
Q21 | 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”)
Q22 | 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”)
Q23 | Which of the following statements are true?
- when you open a file for reading, if the file does not exist, an error occurs
- when you open a file for writing, if the file does not exist, a new file is created
- when you open a file for writing, if the file exists, the existing file is overwritten with the new file
- all of the mentioned
Q24 | 1 TEXT FILES, READING AND WRITING FILES, FORMAT OPERATOR
- infile.read(2)
- infile.read()
- infile.readline()
- infile.readlines()
Q25 | To read the remaining lines of the file from a file object infile, we use
- infile.read(2)
- infile.read()
- infile.readline()
- infile.readlines()