Question:
1. The following is an example of an instruction written in which computer language?
10110000
a. Assembly language
b. Java
c. machine language
d. C#
2. What is the output of the following statement? print('I\'m ready to begin')
a. Im ready to begin
b. I\'m ready to begin
c. I'm ready to begin
d. 'I\'m ready to begin'
3. What is the result of the following Boolean expression, given that x = 5, y = 3, and z = 8?
x < y or z > x
a. True
b. False
c. 8
d. 5
4. What will be displayed after the following code is executed? total = 0 for count in range(1,4): total += count print(total)
a. 1
b. 5
c. 1 4
d. 6
5.What will display after the following code is executed?def main print("The answer is",magic(5) )def magic(num):answer = num + 2 * 10return answer if __name__ == '__main__': main()
a. 70
b. 25
c. 100
d. The statement will cause a syntax error.
6.Which of the following is the correct way to open a file named users.txt in 'r' mode?
a. infile = open('r', users.txt)
b. infile = read('users.txt', 'r')
c. infile = open('users.txt', 'r')
d. infile = readlines('users.txt', r)
7. What will be the value of the variable list2 after the following code executes?
list1 = [1, 2, 3]
list2 = []
for element in list1:
list2.append(element)
list1 = [4, 5, 6]
a. [1, 2, 3]
b. [4, 5, 6]
c. [1, 2, 3, 4, 5, 6]
d. Nothing; this code is invalid
8.What will be displayed after the following code executes?
mystr = 'yes'
yourstr = 'no'
mystr += yourstr * 2
print(mystr)
a. yes + no * 2
b. yes + no yes + no
c. Yesnono
d. Yesnoyesno
9. What is the value of the dictionary variable phones here after the following code executes?
phones = {'John' : '5555555', 'Julie' : '5557777'}
phones['John'] = ‘5556666’
a. {'John' : '5555555', 'Julie' : '5557777'}
b. {'John' : '5556666', 'Julie' : '5557777'}
c. {'John' : '5556666'}
d. This code is invalid.
10. Which method is automatically executed when an instance of a class is created in memory?
a. __state__
b. __obj__
c. __str__
d. __init__
11. Which widget creates an area that displays one line of text or an image?
a. Label
b. Canvas
c. Message
d. Text
12. Given the following code, which line defines the size of the window?
shape = myShape()
a. self.main_window = tkinter.Tk()
b. self.canvas = tkinter.Canvas(self.main_window,width=200, height=200)
c. self.canvas.create_rectangle(30,30, 175, 175)
d. shape = myShape()
13. To open a file c:\scores.txt for writing, use __________.
A. infile = open("c:\scores.txt", "w")
B. infile = open(file = "c:\scores.txt", "w")
C. infile = open(file = "c:\\scores.txt", "w")
D. infile = open("c:\\scores.txt", "w")
14. Suppose dictionary = {"john":40, "peter":45}, to obtain the number of entries in dictionary, use ________.
A. dictionary.len()
B. dictionary.size()
C. len(dictionary)
D. size(dictionary)
15.What is the printout of the following code?
dictionary = {"john":40, "peter":45}
print(list(dictionary.values()))
A. ["john", "peter"]
B. ("john":40, "peter":45)
C. [40, 45]
D. ["john":40, "peter":45]
E. ("john", "peter")