CIS 221 Final

¡Supera tus tareas y exámenes ahora con Quizwiz!

_______ is a template, blueprint, or contract that defines objects of the same type. A. A class B. An object C. A method D. A data field

A. A class

________ is used to create an object. A. A constructor B. A class C. A value-returning method D. A None method

A. A constructor

The word True is ________. (multiple) A. a Python keyword B. a Boolean literal C. same as value 1 D. same as value 0

A. a Python keyword B. a Boolean literal

What is chr(ord('B')))? A. A B. B C. C D. D

B. B

__________ is the brain of a computer. A. Hardware B. CPU C. Memory D. Disk

B. CPU

list1 = [11, 2, 23] and list2 = [11, 2, 2], list1 < list2 is ________ A. True B. False

B. False

random.randint(0, 1) returns ____________. A. 0 B. 1 C. 0 or 1 D. 2

C. 0 or 1

Each time a function is invoked, the system stores parameters and local variables in an area of memory, known as _______, which stores elements in last-in first-out fashion. A. a heap B. storage area C. a stack D. an array

C. a stack

Suppose x is a char variable with a value 'b'. What will be displayed by the statement print(chr(ord(x) + 1))? A. a B. b C. c D. d

C. c

To bind a canvas with a key event p, use __________ A. canvas.entered(p) B. canvas.bind("<Enter>", p) C. canvas.bind("<Key>", p) D. canvas.bind(<Enter>, p) E. canvas.bind("<Enter>", p)

C. canvas.bind("<Key>", p)

x = 1 y = x = x + 1 print("y is", y) A. y is 0. B. y is 1 because x is assigned to y first. C. y is 2 because x + 1 is assigned to x and then x is assigned to y. D. The program has a compile error since x is redeclared in the statement int y = x = x + 1.

C. y is 2 because x + 1 is assigned to x and then x is assigned to y.

To set the pen size to 5 pixels, use _________. A. turtle.setSize(5) B. turtle.size(5) C. turtle.pensize(5) D. turtle.setPenSize(5)

C. turtle.pensize(5)

How do you create an event loop? A. window.loop() B. window.main() C. window.mainloop() D. window.eventloop()

C. window.mainloop()

Which of the following statements are the same? (A) x -= x + 4 (B) x = x + 4 - x (C) x = x - (x + 4) A. (A) and (B) are the same B. (A) and (C) are the same C. (B) and (C) are the same D. (A), (B), and (C) are the same

B. (A) and (C) are the same

To check whether a char variable ch is an uppercase letter, you write ___________. (multiple) A. (ch >= 'A' and ch >= 'Z') B. (ch >= 'A' and ch <= 'Z') C. (ch >= 'A' or ch <= 'Z') D. ('A' <= ch <= 'Z')

B. (ch >= 'A' and ch <= 'Z') D. ('A' <= ch <= 'Z')

If a function does not return a value, by default, it returns ___________. A. None B. int C. double D. public E. null

A. None

_____________ is a program that runs on a computer to manage and control a computer's activities. A. Operating system B. Python C. Modem D. Interpreter E. Compiler

A. Operating system

What is "Programming is fun"[:2]? A. Pr B. P C. Pro D. Programming E. Programming is

A. Pr

________ is interpreted. A. Python B. C++ C. C D. Ada E. Pascal

A. Python

What is displayed when the following program is run? try: list = 10 * [0] x = list[9] print("Done") except IndexError: print("Index out of bound") else: print("Nothing is wrong") finally: print("Finally we are here") A. "Done" followed by "Nothing is wrong" B. "Done" followed by "Nothing is wrong" followed by "Finally we are here" C. "Index out of bound" followed by "Nothing is wrong" followed by "Finally we are here" D. "Nothing is wrong" followed by "Finally we are here"

B. "Done" followed by "Nothing is wrong" followed by "Finally we are here"

You can create an image from a ____________ file. A. .png B. .gif C. .bmp D. .jpg

B. .gif

What will be displayed by the following code? myList = [1, 5, 5, 5, 5, 1] max = myList[0] indexOfMax = 0 for i in range(1, len(myList)): if myList[i] > max: max = myList[i] indexOfMax = i print(indexOfMax) A. 0 B. 1 C. 2 D. 3 E. 4

B. 1

The following loop displays _______________. for i in range(1, 11): print(i, end = " ") A. 1 2 3 4 5 6 7 8 9 B. 1 2 3 4 5 6 7 8 9 10 C. 1 2 3 4 5 D. 1 3 5 7 9 E. 2 4 6 8 10

B. 1 2 3 4 5 6 7 8 9 10

What is the result of 45 // 4? A. 10 B. 11 C. 11.25 D. 12

B. 11

2 * 3 ** 2 evaluates to __________. A. 36 B. 18 C. 12 D. 81

B. 18

Given a string s = "Welcome", what is s.count('e')? A. 1 B. 2 C. 3 D. 4

B. 2

Which of the following functions is incorrect? (multiple) A. range(0, 3.5) B. range(10, 4, -1) C. range(1, 3, 1) D. range(2.5, 4.5) E. range(1, 2.5, 4.5)

A. range(0, 3.5) D. range(2.5, 4.5) E. range(1, 2.5, 4.5)

To return the length of string s, use _________. (multiple) A. s.__len__() B. len(s) C. size(s) D. s.size()

A. s.__len__() B. len(s)

To check whether string s1 contains s2, use _________. (multiple) A. s1.__contains__(s2) B. s1 in s2 C. s1.contains(s2) D. si.in(s2)

A. s1.__contains__(s2) B. s1 in s2

To concatenate two strings s1 and s2 into s3, use _________. (multiple) A. s3 = s1 + s2 B. s3 = s1.add(s2) C. s3 = s1.__add(s2) D. s3 = s1.__add__(s2)

A. s3 = s1 + s2 D. s3 = s1.__add__(s2)

To retrieve the character at index 3 from string s, use _________. (multiple) A. s[3] B. s.getitem(3) C. s.__getitem__(3) D. s.getItem(3)

A. s[3] C. s.__getitem__(3)

The ________ creates an object in the memory and invokes __________. A. the __init__ method B. the init method C. the initialize method D. the __str__ method

A. the __init__ method

To display a message dialog named "Programming is fun", use __________ A. tkinter.messagebox.showinfo("showinfo", "Programming is fun") B. tkinter.messagebox.showwarning("showwarning", "Programming is fun") C. tkinter.messagebox.showerror("showerror", "Programming is fun") D. tkinter.messagebox.askyesno("ashyesno", "Programming is fun")

A. tkinter.messagebox.showinfo("showinfo", "Programming is fun")

To draw a circle with radius 50, use ___________. A. turtle.circle(50) B. turtle.circle(100) C. turtle.drawcircle(50) D. turtle.drawCircle(50)

A. turtle.circle(50)

To set a turtle drawing speed to 5, use _________. A. turtle.speed(5) B. turtle.setSpeed(5) C. turtle.setspeed(5) D. turtle.velocity(5)

A. turtle.speed(5)

The mouse event object has the property ____________. (multiple) A. x B. y C. widget D. X E. Y

A. x B. y C. widget

Which of the following is the correct expression of character 4? (multiple) A. 4 B. "4" C. '4'

B. "4" C. '4'

What is displayed when the following program is run? try: list = 5 * [0] x = list[5] print("Done") except IndexError: print("Index out of bound") A. "Done" followed by "Index out of bound" B. "Index out of bound" C. "Done" D. Nothing displayed

B. "Index out of bound"

A function _________. A. must have at least one parameter B. may have no parameters C. must always have a return statement to return a value D. must always have a return statement to return multiple values

B. may have no parameters

Which of the following is a valid identifier? (multiple) A. $343 B. mile C. 9X D. 8+9 E. max_radius

B. mile E. max_radius

Which of the following is a valid identifier? (multiple) A. import B. mile1 C. MILE D. (red) E. "red"

B. mile1 C. MILE

What is the number of iterations in the following loop: for i in range(1, n + 1): # iteration A. 2*n B. n C. n - 1 D. n + 1

B. n

In the expression 45 / 4, the values on the left and right of the / symbol are called ____. A. operators B. operands C. parameters D. arguments

B. operands

To open a file c:\scores.txt for writing, use __________. A. outfile = open("c:\scores.txt", "w") B. outfile = open("c:\\scores.txt", "w") C. outfile = open(file = "c:\scores.txt", "w") D. outfile = open(file = "c:\\scores.txt", "w")

B. outfile = open("c:\\scores.txt", "w")

Arguments to functions always appear within __________. A. brackets B. parentheses C. curly braces D. quotation marks

B. parentheses

When you invoke a function with a parameter, the value of the argument is passed to the parameter. This is referred to as _________. A. function invocation B. pass by value C. pass by reference D. pass by name

B. pass by value

Which of the following statement prints smith\exam1\test.txt? A. print("smith\exam1\test.txt") B. print("smith\\exam1\\test.txt") C. print("smith\"exam1\"test.txt") D. print("smith"\exam1"\test.txt")

B. print("smith\\exam1\\test.txt")

What is "Programming is fun"[4: 6]? A. ram B. ra C. r D. pr E. pro

B. ra

Which of the following function returns a sequence 0, 1, 2, 3? (multiple) A. range(0, 3) B. range(0, 4) C. range(3) D. range(4)

B. range(0, 4) D. range(4)

Which of the following statements is correct? A. s = "Chapter " + 1 B. s = "Chapter " + str(1)

B. s = "Chapter " + str(1)

To display a warning dialog named "Variable is assigned, but not used", use __________ A. tkinter.messagebox.showinfo("showinfo", "Variable is assigned, but not used") B. tkinter.messagebox.showwarning("showwarning", "Variable is assigned, but not used") C. tkinter.messagebox.showerror("showerror", "PVariable is assigned, but not used") D. tkinter.messagebox.askyesno("ashyesno", "Variable is assigned, but not used")

B. tkinter.messagebox.showwarning("showwarning", "Variable is assigned, but not used")

To put the pen down, use ___________. A. turtle.penDown() B. turtle.pendown() C. turtle.putDown() D. turtle.down()

B. turtle.pendown()

To lift the pen, use ___________. A. turtle.penUp() B. turtle.penup() C. turtle.lift() D. turtle.up()

B. turtle.penup()

Assume x = 14 and y = 15, Which of the following is true? (multiple) A. x % 2 == 0 and y % 2 == 0 B. x % 2 == 0 and y % 2 == 1 C. x % 2 == 0 or y % 2 == 0 D. x % 2 != 0 and y % 2 != 0

B. x % 2 == 0 and y % 2 == 1 C. x % 2 == 0 or y % 2 == 0

To add a value 1 to variable x, you write (multiple) A. 1 + x = x B. x += 1 C. x := 1 D. x = x + 1 E. x = 1 + x

B. x += 1 D. x = x + 1 E. x = 1 + x

Given |x - 2| >= 4, Which of the following is true? A. x - 2 >= 4 and x - 2 <= -4 B. x - 2 >= 4 or x - 2 <= -4 C. x - 2 >= 4 and x - 2 < -4 D. x - 2 >= 4 or x - 2 <= -4

B. x - 2 >= 4 or x - 2 <= -4

Assume x = 4 and y = 5, Which of the following is true? A. x < 5 and y < 5 B. x < 5 or y < 5 C. x > 5 and y > 5 D. x > 5 or y > 5

B. x < 5 or y < 5

What is the output of the following code? x = 0 if x < 4: x = x + 1 print("x is", x) A. x is 0 B. x is 1 C. x is 2 D. x is 3 E. x is 4

B. x is 1

What is x after the following statements? x = 1 x *= x + 1 A. x is 1 B. x is 2 C. x is 3 D. x is 4

B. x is 2

What is displayed when the following program is run? def main(): try: f() print("After the function call") except ZeroDivisionError: print("Divided by zero!") except: print("Exception") def f(): print(1 / 0) main() A. "After the function call" followed by "Divided by zero!" B. "After the function call" C. "Divided by zero!" D. "Divided by zero!" followed by "Exception"

C. "Divided by zero!"

A Python line comment begins with ________. A. // B. /* C. # D. $$

C. #

A Python paragraph comment uses the style ________. A. // comments // B. /* comments */ C. ''' comments ''' D. /# comments #/

C. ''' comments '''

The order of the precedence (from high to low) of the operators +, *, and, or is: A. and, or, *, + B. *, +, and, or C. *, +, and, or D. *, +, or, and E. or, and, *, +

C. *, +, and, or

If a key is not in the list, the binarySearch function returns _________. A. insertion point B. insertion point - 1 C. -(insertion point + 1) D. -insertion point

C. -(insertion point + 1)

To following code reads two number. Which of the following is the correct input for the code? x, y = eval(input("Enter two numbers: ")) A. 1 2 B. "1 2" C. 1, 2 D. 1, 2,

C. 1, 2

How many times will the following code print "Welcome to Python"? count = 0 while count < 10: print("Welcome to Python") count += 1 A. 8 B. 9 C. 10 D. 11 E. 0

C. 10

What is the result of 45 / 4? A. 10 B. 11 C. 11.25 D. 12

C. 11.25

Given the following function def nPrint(message, n): while n > 0: print(message) n -= 1 What is k after invoking nPrint("A message", k)? k = 2 nPrint("A message", k) A. 0 B. 1 C. 2 D. 3

C. 2

Given the following function def nPrint(message, n): while n > 0: print(message) n -= 1 What is k after invoking nPrint("A message", k)? k = 2 nPrint(n = k, message = "A message") A. 0 B. 1 C. 2 D. 3

C. 2

What will be displayed by the following code? myList = [1, 2, 3, 4, 5, 6] for i in range(1, 6): myList[i - 1] = myList[i] for i in range(0, 6): print(myList[i], end = " ") A. 2 3 4 5 6 1 B. 6 1 2 3 4 5 C. 2 3 4 5 6 6 D. 1 1 2 3 4 5 E. 2 3 4 5 6 1

C. 2 3 4 5 6 6

What will be displayed when the following code is executed? number = 6 while number > 0: number -= 3 print(number, end = ' ') A. 6 3 0 B. 6 3 C. 3 0 D. 3 0 -3 E. 0 -3

C. 3 0

What is math.radians(30) * 6? A. 0.0 B. 1.3434343 C. 3.141592653589793 D. 5.565656

C. 3.141592653589793

What is the output for y? y = 0 for i in range(10, 1, -2): y += i print(y) A. 10 B. 40 C. 30 D. 20

C. 30

Given a string s = "Programming is fun", what is s.find('m')? A. 8 B. 7 C. 6 D. 5 E. -1

C. 6

Suppose list1 is [1, 3, 2], what is sum(list1)? A. 5 B. 4 C. 6 D. 2 E. 1

C. 6

What is round(6.5)? A. 4 B. 5 C. 6 D. 7 E. 8

C. 6

Suppose list1 is [3, 4, 5, 20, 5, 25, 1, 3], what is len(list1)? A. 6 B. 7 C. 8 D. 5 E. 4

C. 8

The event _____________ is fired when the right mouse button is released. A. <ButtonReleased-1> B. <ButtonReleased-2> C. <ButtonReleased-3> D. <ButtonPressed-1> E. <ButtonPressed-2>

C. <ButtonReleased-3>

The event _____________ is fired when the right mouse button is double-clicked. A. <Double-Button-1> B. <Double-Button-2> C. <Double-Button-3> D. <Triple-Button-1> E. <Triple-Button-2>

C. <Double-Button-3>

The equal comparison operator is __________. A. <> B. != C. == D. =

C. ==

What will be displayed by the following code? ? (note ? represents a blank space) print(format("Welcome", ">10s"), end = '#') print(format(111, "<4d"), end = '#') print(format(924.656, ">10.2f")) A. ???Welcome#?111#924.66 B. ???Welcome#?111#????924.66 C. ???Welcome#111?#????924.66 D. Welcome???#111?#????924.66

C. ???Welcome#111?#????924.66

What will be displayed by the following code? print("A", end = ' ') print("B", end = ' ') print("C", end = ' ') print("D", end = ' ') A. ABCD B. A, B, C, D C. A B C D D. A, B, C, D will be displayed on four lines

C. A B C D

Which of the following loops correctly computes 1/2 + 2/3 + 3/4 + ... + 99/100? A: sum = 0 for i in range(1, 99): sum += i / (i + 1) print("Sum is", sum) B: sum = 0 for i in range(1, 100): sum += i / (i + 1) print("Sum is", sum) C: sum = 0 for i in range(1.0, 99.0): sum += i / (i + 1) print("Sum is", sum) D: sum = 0 for i in range(1.0, 100.0): sum += i / (i + 1) print("Sum is", sum) A. BCD B. ABCD C. B D. CDE E. CD

C. B

How many times will the following code print "Welcome to Python"? count = 0 while count < 10: print("Welcome to Python") A. 8 B. 9 C. 10 D. 11 E. infinite number of times

E. infinite number of times

The time.time() returns ________________ . A. the current time. B. the current time in milliseconds. C. the current time in milliseconds since midnight. D. the current time in milliseconds since midnight, January 1, 1970. E. the current time in milliseconds since midnight, January 1, 1970 GMT (the Unix time).

E. the current time in milliseconds since midnight, January 1, 1970 GMT (the Unix time).

To move the turtle to a point at (4, 5), use ___________. A. turtle.move(4, 5) B. turtle.moveTo(4, 5) C. turtle.moveto(4, 5) D. turtle.go(4, 5) E. turtle.goto(4, 5)

E. turtle.goto(4, 5)

What is the output of the following code? x = 0 while x < 4: x = x + 1 print("x is", x) A. x is 0 B. x is 1 C. x is 2 D. x is 3 E. x is 4

E. x is 4

True or False: We use the Split method to split on only spaces

False

True or False: print(chr(4)) will display 4

False

Which of the following is NOT a logic error when calculating the average of No1 & No2 a. (No1 + No2)/2 b. they are all logic errors c. No1 + No2/2 d. 2/(No1 + No2)

a. (No1 + No2)/2

Which order of Operator Precedence, from first to last, is correct? (multiple) a. ** not < and = b. > * and =! c. or and not d. not and or

a. ** not < and = d. not and or

What is the index of the first character in a string? a. 0 b. 1 c. 2 d. 3

a. 0

In this statement a = b = c = 9, what is the value of b? a. 9 b. unknown c. 3 d. 0

a. 9

What will the following statement print? print(max(1,5,7,2,9,3)) a. 9 b. 3 c. 157293 d. 1

a. 9

Mark all of the following that are strings: (multiple) a. Five b. 5Apples c. eval(5) d. Apples e. Apples5

a. Five b. 5Apples d. Apples e. Apples5

Suppose string s1 is JMU, what would the following code do? s1 * 2 a. JMUJMU b. Cause an error c. 6 d. True

a. JMUJMU

Which function finds the length of a string? a. Len b. There is no way to find the length of a string c. Length d. L

a. Len

What is used to break a long statement into multiple lines? a. \ b. + c. and d. more

a. \

What is y after the following statements are executed? x = 0 y = "red" if x > 0 else "blue" a. blue b. red c. same as x d. 0

a. blue

In this list below, which fruit is at index 2? apple banana cherry date elderberry a. cherry b. apple c. elderberry d. date e. banana

a. cherry

What does the str function do? a. converts a number into a string b. i made it up c. converts a string to a number d. changes the variable to str

a. converts a number into a string

Assume x = 14 and y = 15, Which 2 of the following is true? (multiple) a. (x % 2 == 0 and y % 2 == 0) b. (x % 2 == 0 and y % 2 == 1) c. (x % 2 == 0 or y % 2 == 0) d. (x % 2 != 0 and y % 2 != 0)

b. (x % 2 == 0 and y % 2 == 1) c. (x % 2 == 0 or y % 2 == 0)

What will print if x = 10 if x >= 10: print ("10 or larger") a. (space) b. 10 or larger c. nothing d. 10

b. 10 or larger

How many times will this loop execute: for x in range (2, 4): print (x) a. 4 b. 2 c. 1 d. 3 e. 0

b. 2

One byte has ____ bits. a. 4 b. 8 c. 12 d. 16

b. 8

What is the result of "JMU" == "James Madison U" a. True b. False c. James Madison U d. Nothing, causes an error

b. False

Which of the following is the same as this: a *= b a. b = a * b b. a = a * b c. a * b = b d. b * a = a

b. a = a * b

Which statement will give me a random number between 1 & 5 inclusive (meaning only numbers 1 2 3 4 or 5) a. random.randint (0, 6) b. random.randint (1, 5) c. random.randint(0, 9) d. random.int (1, 5)

b. random.randint (1, 5)

Python's print statement will print to the a. printer b. screen c. USB or thumb drive

b. screen

Python has a graphics module called a. command b. turtle c. drawing d. graphics

b. turtle

What is the result of 25 % 4 a. 4 b. 2 c. 1 d. 24

c. 1

One gigabyte is approximately ________ bytes. a. 1 million b. 10 million c. 1 billion d. 1 trillion

c. 1 billion

How many times will this loop execute: for x in range(2): print(x) a. 1 b. 0 c. 2 d. endless

c. 2

How many times will this loop body repeat? number = 0 while number < 9: number += 1 a. 0 b. 8 c. 9 d. 10 e. 1

c. 9

If a string has 10 characters, what is the index of the last character? a. 0 b. 8 c. 9 d. 10 e. 1

c. 9

A ___________ error does not cause the program to abort, but produces incorrect results. a. syntax b. runtime c. logic

c. logic

To display a number with %, which one of the following will work? a. print (format 0.53, 10.2%) b. print (format (0.53, "10.2$")) c. print (format (0.53, "10.2%")) d. print (format (0.53, 10.2%))

c. print (format (0.53, "10.2%"))

What does this contain? newlist = list("xyz") a. the syntax is wrong b. that is not a list, it is just letters c. x, y, z d. xyz

c. x, y, z

How many times will the following loop execute? x = 0 y = 0 while x < y: x = x + 1 y = y + 2 a. 2 b. endless c. 1 d. 0

d. 0

____________ is a device to connect a computer to a local area network (LAN). a. regular modem b. DSL c. cable modem d. NIC

d. NIC

The 2 types of loops we will study are: a. Iteration b. Next c. Count d. While e. Continue f. For

d. While f. For

What is the result of print (int ("5.9")) a. 5 b. 0 c. 6 d. causes an error e. 9

d. causes an error

Python is a ____________ language. a. compiled b. neither c. both d. interpreted

d. interpreted

Suppose list1 is [3, 4, 5, 20, 5, 25, 1, 3], what is min(list1)? A. 5 B. 4 C. 8 D. 25 E. 1

E. 1

What is "Programming is fun"[-3:-1]? A. Pr B. P C. fun D. un E. fu

E. fu

How many times is the print statement executed? for i in range(10): for j in range(10): print(i * j) A. 100 B. 20 C. 10 D. 45

A. 100

Given a string s = "Programming is fun", what is s.rfind('m')? A. 8 B. 7 C. 6 D. 5 E. -1

B. 7

What is the result of eval("1 + 3 * 2")? A. "1 + 3 * 2" B. 7 C. 8 D. "1 + 6"

B. 7

2 ** 3 evaluates to __________. A. 9 B. 8 C. 9.0 D. 8.0

B. 8

The format function returns _______. A. an int B. a float C. a str

B. a str

What is "Programming is fun"[-1]? A. Pr B. P C. fun D. n E. un

D. n

Which of the following statements are True? (multiple) A. (x > 0 and x < 10) is same as (x > 0 and x < 10) B. (x > 0 or x < 10) is same as (0 < x < 10) C. (x > 0 or x < 10 and y < 0) is same as (x > 0 or (x < 10 and y < 0)) D. (x > 0 or x < 10 and y < 0) is same as ((x > 0 or x < 10) and y < 0)

A. (x > 0 and x < 10) is same as (x > 0 and x < 10) C. (x > 0 or x < 10 and y < 0) is same as (x > 0 or (x < 10 and y < 0))

What is y after the following statement is executed? x = 0 y = 10 if x > 0 else -10 A. -10 B. 0 C. 10 D. 20 E. Illegal expression

A. -10

Suppose x is 1. What is x after x -= 1? A. 0 B. 1 C. 2 D. -1 E. -2

A. 0

Which of the following is equivalent to 0.025? (multiple) A. 0.25E-1 B. 2.5e-2 C. 0.0025E1 D. 0.00025E2 E. 0.0025E+1

A. 0.25E-1 B. 2.5e-2 C. 0.0025E1 D. 0.00025E2 E. 0.0025E+1

What is min(3, 5, 1, 7, 4)? A. 1 B. 3 C. 5 D. 7 E. 4

A. 1

Which of the following expressions will yield 0.5? (multiple) A. 1 / 2 B. 1.0 / 2 C. 1 // 2 D. 1.0 // 2 E. 1 / 2.0

A. 1 / 2 B. 1.0 / 2 E. 1 / 2.0

What is sum after the following loop terminates? sum = 0 item = 0 while item < 5: item += 1 sum += item if sum >= 4: continue print(sum) A. 15 B. 16 C. 17 D. 18

A. 15

What will be displayed by print(ord('z') - ord('a'))? A. 25 B. 26 C. a D. z

A. 25

__________ is a simple but incomplete version of a function. A. A stub B. A function C. A function developed using botton-up approach D. A function developed using top-down approach

A. A stub

How do you create a canvas under parent frame1 with background color white and foregroung color green? A. Canvas(frame1, bg = "white", fg = "green") B. Canvas(frame1, bg = "white", fg = "green", command = processEvent) C. Canvas(frame1, bg = "white", command = processEvent) D. Canvas(frame1, fg = "green", command = processEvent)

A. Canvas(frame1, bg = "white", fg = "green")

Which of the following statements are true? (multiple) A. Each object has a unique id. B. Objects of the same type have the same id. C. Objects of the same kind have the same type. D. A variable that holds a value is actually a reference to an object for the value.

A. Each object has a unique id. C. Objects of the same kind have the same type. D. A variable that holds a value is actually a reference to an object for the value.

What will be displayed by the following code? ch = 'F' if ch >= 'A' and ch <= 'Z': print(ch) A. F B. f C. nothing D. F f

A. F

________ is the physical aspect of the computer that can be seen. A. Hardware B. Software C. Operating system D. Application program

A. Hardware

________ is an object-oriented programming language. (multiple) A. Java B. C++ C. C D. C# E. Python

A. Java B. C++ D. C# E. Python

The side option of the pack manager may be _____________. (multiple) A. LEFT B. RIGHT C. BOTTOM D. TOP

A. LEFT B. RIGHT C. BOTTOM D. TOP

Analyze the following code: class MyDate: def __init__(self, year, month, day): self.year = year self.month = month self.day = day class Name: def __init__(self, firstName, mi, lastName, birthDate): self.firstName = firstName self.mi = mi self.lastName = lastName self.birthDate = birthDate birthDate = MyDate(1990, 1, 1) name = Name("John", 'F', "Smith", birthDate) birthDate = MyDate(1991, 1, 1) birthDate.year = 1992 print(name.birthDate.year) A. The program displays 1990. B. The program displays 1991. C. The program displays 1992. D. The program displays no thing.

A. The program displays 1990.

What is the value of the following expression? True or True and False A. True B. False

A. True

Which of the Boolean expressions below is incorrect? (multiple) A. True and 3 => 4 B. !(x > 0) and (x > 0) C. (x > 0) or (x < 0) D. (x != 0) or (x = 0) E. (-10 < x < 0)

A. True and 3 => 4 B. !(x > 0) and (x > 0) D. (x != 0) or (x = 0)

Which of the following statements are true? (multiple) A. When you open a file for reading, if the file does not exist, an error occurs. B. When you open a file for writing, if the file does not exist, an error occurs. C. When you open a file for reading, if the file does not exist, the program will open an empty file. D. When you open a file for writing, if the file does not exist, a new file is created. E. When you open a file for writing, if the file exists, the existing file is overwritten with the new file.

A. When you open a file for reading, if the file does not exist, an error occurs. D. When you open a file for writing, if the file does not exist, a new file is created. E. When you open a file for writing, if the file exists, the existing file is overwritten with the new file.

Which of the following should be defined as a None function? A. Write a function that prints integers from 1 to 100. B. Write a function that returns a random integer from 1 to 100. C. Write a function that checks whether current second is an integer from 1 to 100. D. Write a function that converts an uppercase letter to lowercase.

A. Write a function that prints integers from 1 to 100.

Will the following program terminate? balance = 10 while True: if balance < 9: break balance = balance - 9 A. Yes B. No

A. Yes

"Welcome to Python".split() is ________ A. ["Welcome", "to", "Python"] B. ("Welcome", "to", "Python") C. {"Welcome", "to", "Python"} D. "Welcome", "to", "Python"

A. ["Welcome", "to", "Python"]

What is list("a#b#c#d".split('#')? A. ['a', 'b', 'c', 'd'] B. ['a b c d'] C. ['a#b#c#d'] D. ['abcd']

A. ['a', 'b', 'c', 'd']

What is list("abcd")? A. ['a', 'b', 'c', 'd'] B. ['ab'] C. ['cd'] D. ['abcd']

A. ['a', 'b', 'c', 'd']

Suppose list1 is [3, 4, 5, 20, 5, 25, 1, 3], what is list1 after list1.extend([34, 5])? A. [3, 4, 5, 20, 5, 25, 1, 3, 34, 5] B. [1, 3, 3, 4, 5, 5, 20, 25, 34, 5] C. [25, 20, 5, 5, 4, 3, 3, 1, 34, 5] D. [1, 3, 4, 5, 20, 5, 25, 3, 34, 5] E. [3, 1, 25, 5, 20, 5, 4, 3, 34, 5]

A. [3, 4, 5, 20, 5, 25, 1, 3, 34, 5]

Suppose list1 is [3, 4, 5, 20, 5, 25, 1, 3], what is list1 after list1.pop()? A. [3, 4, 5, 20, 5, 25, 1] B. [1, 3, 3, 4, 5, 5, 20, 25] C. [3, 5, 20, 5, 25, 1, 3] D. [1, 3, 4, 5, 20, 5, 25] E. [3, 1, 25, 5, 20, 5, 4]

A. [3, 4, 5, 20, 5, 25, 1]

A variable defined outside a function is referred to as __________. A. a global variable B. a function variable C. a block variable D. a local variable

A. a global variable

You can display an image in ______________. (multiple) A. a label B. a button C. a check button D. a radio button E. an entry

A. a label B. a button C. a check button D. a radio button

To add 0.01 + 0.02 + ... + 1.00, what order should you use to add the numbers to get better accuracy? A. add 0.01, 0.02, ..., 1.00 in this order to a sum variable whose initial value is 0. B. add 1.00, 0.99, 0.98, ..., 0.02, 0.01 in this order to a sum variable whose initial value is 0.

A. add 0.01, 0.02, ..., 1.00 in this order to a sum variable whose initial value is 0.

If the binary search function returns -4, where should the key be inserted if you wish to insert the key into the list? A. at index 3 B. at index 4 C. at index 5 D. at index 6

A. at index 3

How do you display a text "Good morning" centered at 30, 40 with color red? A. canvas.create_text(30, 40, text = "Good morning", fill = "red") B. canvas.create_polygon(30, 40, 50, 50, 10, 100, filled = "red") C. canvas.create_polygon(30, 40, 50, 50, 10, 100, fill = "red") D. canvas.create_polygon((30, 40), (50, 50), (10, 100), fill = "red")

A. canvas.create_text(30, 40, text = "Good morning", fill = "red")

If a number is too large to be stored in memory, it _____________. A. causes overflow B. causes underflow C. causes no error D. cannot happen in Python

A. causes overflow

Analyze the following code. (multiple) count = 0 while count < 100: # Point A print("Welcome to Python!") count += 1 # Point B # Point C A. count < 100 is always True at Point A B. count < 100 is always True at Point B C. count < 100 is always False at Point B D. count < 100 is always True at Point C E. count < 100 is always False at Point C

A. count < 100 is always True at Point A E. count < 100 is always False at Point C

Assume name = StringVar(), how do you create a text field (entry) under parent frame2 with variable bound to name? A. entryName = Entry(frame2, textvariable = name) B. entryName = Entry(frame2, variable = name, value = "") C. entryName = Entry(frame2, textvariable = name, command = processEntry) D. entryName = Entry(frame2, text = name, command = processEntry)

A. entryName = Entry(frame2, textvariable = name)

Given the following function header: def f(p1, p2, p3, p4) Which of the following is correct to invoke it? (multiple) A. f(1, 2, 3, 4) B. f(p1 = 1, 2, 3, 4) C. f(p1 = 1, p2 = 2, p3 = 3, 4) D. f(p1 = 1, p2 = 2, p3 = 3, p4 = 4) E. f(1, 2, 3, p4 = 4)

A. f(1, 2, 3, 4) D. f(p1 = 1, p2 = 2, p3 = 3, p4 = 4) E. f(1, 2, 3, p4 = 4)

_____________ displays a file dialog for opening an existing file. A. filename = askopenfilename() B. filename = asksaveasfilename() C. filename = openfilename() D. filename = saveasfilename()

A. filename = askopenfilename()

Which of the following are storage devices? (multiple) A. floppy disk B. hard disk C. flash stick D. CD-ROM

A. floppy disk B. hard disk C. flash stick D. CD-ROM

To format a number x to 3 digits after the decimal point, use _______. A. format(x, "5.3f") B. format("5.3f", x) C. format(x, "5.4f") D. format("5.3f", x)

A. format(x, "5.3f")

Whenever possible, you should avoid using __________. A. global variables B. function parameters C. global constants D. local variables

A. global variables

To open a file c:\scores.dat for binary reading, use __________. A. infile = open("c:\\scores.dat", "rb") B. infile = open("c:\\scores.dat", "r") C. infile = open("c:\scores.dat", "wrb") D. infile = open("c:\\scores.dat", "r")

A. infile = open("c:\\scores.dat", "rb")

_____________ opens a URL for input. A. infile = urllib.request.urlopen(urlString) B. infile = urllib.urlopen(urlString) C. infile = request.urlopen(urlString) D. infile = urlopen(urlString)

A. infile = urllib.request.urlopen(urlString)

To read two characters from a file object infile, use _________. A. infile.read(2) B. infile.read() C. infile.readline() D. infile.readlines()

A. infile.read(2)

What function do you use to read a string? A. input("Enter a string") B. eval(input("Enter a string")) C. enter("Enter a string") D. eval(enter("Enter a string"))

A. input("Enter a string")

__________ creates a list. (multiple) A. list1 = list() B. list1 = [] C. list1 = list([12, 4, 4]) D. list1 = [12, 4, 4] E. list1 = [1, "3", "red"]

A. list1 = list() B. list1 = [] C. list1 = list([12, 4, 4]) D. list1 = [12, 4, 4] E. list1 = [1, "3", "red"]

To remove string "red" from list1, use _______. A. list1.remove("red") B. list1.remove(red) C. list1.removeAll("red") D. list1.removeOne("red")

A. list1.remove("red")

Computer can execute the code in ____________. A. machine language B. assembly language C. high-level language D. none of the above

A. machine language

To add a menu in a menubar, use __________ A. menu1 = Menu(menubar) B. menu1 = menu(menubar) C. menu1 = Menu(winodw) D. menu1 = Menu()

A. menu1 = Menu(menubar)

To create a menu in a window, use __________ A. menubar = Menu(window) B. menubar = MenBar(window) C. menubar = Menu() D. menubar = MenBar()

A. menubar = Menu(window)

Which of the following is equivalent to x != y? (multiple) A. not (x == y) B. x > y and x < y C. x > y or x < y D. x >= y or x <= y

A. not (x == y) C. x > y or x < y

If a class defines the __str__(self) method, for an object obj for the class, you can use ______ to invoke the __str__ method. (multiple) A. obj.__str__() B. str(obj) C. obj.str() D. __str__(obj)

A. obj.__str__() B. str(obj)

To open a file c:\scores.dat for binary writing, use __________. A. outfile = open("c:\\scores.dat", "wb") B. outfile = open("c:\\scores.dat", "w") C. outfile = open("c:\scores.dat", "a") D. outfile = open("c:\\scores.dat", "w")

A. outfile = open("c:\\scores.dat", "wb")

To open a file c:\scores.txt for appending data, use ________ A. outfile = open("c:\\scores.txt", "a") B. outfile = open("c:\\scores.txt", "rw") C. outfile = open(file = "c:\scores.txt", "w") D. outfile = open(file = "c:\\scores.txt", "w")

A. outfile = open("c:\\scores.txt", "a")

_______ are geometry managers in Tkinter. (multiple) A. pack B. grid C. place D. flow

A. pack B. grid C. place

Suppose list1 is [1, 3, 2, 4, 5, 2, 1, 0], Which of the following is correct? (multiple) A. print(list1[0]) B. print(list1[:2]) C. print(list1[:-2]) D. print(list1[4:6])

A. print(list1[0]) B. print(list1[:2]) C. print(list1[:-2]) D. print(list1[4:6])

To generate a random integer between 0 and 5, use ________________. (multiple) A. random.randint(0, 5) B. random.randint(0, 6) C. random.randrange(0, 5) D. random.randrange(0, 6)

A. random.randint(0, 5) D. random.randrange(0, 6)

To insert 5 to the third position in list1, use _______. A. list1.insert(3, 5) B. list1.insert(2, 5) C. list1.add(3, 5) D. list1.append(3, 5)

B. list1.insert(2, 5)

If you enter 1 2 3 in three separate lines, when you run this program, what will be displayed? print("Enter three numbers: ") number1 = eval(input()) number2 = eval(input()) number3 = eval(input()) # Compute average average = (number1 + number2 + number3) / 3 # Display result print(average) A. 1.0 B. 2.0 C. 3.0 D. 4.0

B. 2.0

If you enter 1, 2, 3, in one line, when you run this program, what will be displayed? number1, number2, number3 = eval(input("Enter three numbers: ")) # Compute average average = (number1 + number2 + number3) / 3 # Display result print(average) A. 1.0 B. 2.0 C. 3.0 D. 4.0

B. 2.0

What will be displayed by the following code? x = 1 def f1(): x = 3 print(x) f1() print(x) A. 1 3 B. 3 1 C. The program has a runtime error because x is not defined. D. 1 1 E. 3 3

B. 3 1

What will be displayed by the following code? x = 1 def f1(): y = x + 2 print(y) f1() print(x) A. 1 3 B. 3 1 C. The program has a runtime error because x is not defined. D. 1 1 E. 3 3

B. 3 1

What is sum after the following loop terminates? sum = 0 item = 0 while item < 5: item += 1 sum += item if sum > 4: break print(sum) A. 5 B. 6 C. 7 D. 8

B. 6

What is math.degrees(math.pi / 2)? A. 0.0 B. 90.0 C. 45.0 D. 30.0

B. 90.0

The "less than or equal to" comparison operator is __________. A. < B. <= C. =< D. << E. !=

B. <=

The event _____________ is fired when the mouse is moved while the middle mouse is being held down. A. <B1-Motion> B. <B2-Motion> C. <B3-Motion> D. <Button-1> E. <Button-2>

B. <B2-Motion>

___________ translates high-level language program into machine language program. A. An assembler B. A compiler C. CPU D. The operating system

B. A compiler

Which of the following statement is most accurate? (multiple) A. A reference variable is an object. B. A reference variable refers to an object. C. An object may contain other objects. D. An object may contain the references of other objects.

B. A reference variable refers to an object. D. An object may contain the references of other objects.

__________ represents an entity in the real world that can be distinctly identified. A. A class B. An object C. A method D. A data field

B. An object

Suppose you write the code to display "Cannot get a driver's license" if age is less than 16 and "Can get a driver's license" if age is greater than or equal to 16. Which of the following code is the best? I: if age < 16: print("Cannot get a driver's license") if age >= 16: print("Can get a driver?s license") II: if age < 16: print("Cannot get a driver's license") else: print("Can get a driver's license") III: if age < 16: print("Cannot get a driver's license") elif age >= 16: print("Can get a driver's license") IV: if age < 16: print("Cannot get a driver's license") elif age == 16: print("Can get a driver's license") elif age > 16: print("Can get a driver's license") A. I B. II C. III D. IV

B. II

Suppose income is 4001, what will be displayed by f the following code? if income > 3000: print("Income is greater than 3000") elif income > 4000: print("Income is greater than 4000") A. none B. Income is greater than 3000 C. Income is greater than 3000 followed by Income is greater than 4000 D. Income is greater than 4000 E. Income is greater than 4000 followed by Income is greater than 3000

B. Income is greater than 3000

What will be displayed by the following code? isCorrect = False print("Correct" if isCorrect else "Incorrect") A. Correct B. Incorrect C. nothing D. Correct Incorrect

B. Incorrect

Does the function call in the following function cause syntax errors? import math def main(): math.sin(math.pi) main() A. Yes B. No

B. No

Will the following program terminate? balance = 10 while True: if balance < 9: continue balance = balance - 9 A. Yes B. No

B. No

Which of the following statements is true? A. Python 3 is a newer version, but it is backward compatible with Python 2. B. Python 3 is a newer version, but it is not backward compatible with Python 2. C. A Python 2 program can always run on a Python 3 interpreter. D. A Python 3 program can always run on a Python 2 interpreter.

B. Python 3 is a newer version, but it is not backward compatible with Python 2.

____________ are instructions to the computer. (multiple) A. Hardware B. Software C. Programs D. Keyboards

B. Software C. Programs

Analyze the following code. even = False if even: print("It is even!") A. The code displays It is even! B. The code displays nothing. C. The code is wrong. You should replace if even: with if even == True: D. The code is wrong. You should replace if even: with if even = True:

B. The code displays nothing.

Analyze the following code: class Name: def __init__(self, firstName, mi, lastName): self.firstName = firstName self.mi = mi self.lastName = lastName firstName = "John" name = Name(firstName, 'F', "Smith") firstName = "Peter" name.lastName = "Pan" print(name.firstName, name.lastName) A. The program displays Peter Pan. B. The program displays John Pan. C. The program displays Peter Smith. D. The program displays John Smith.

B. The program displays John Pan.

What is the result of evaluating 2 + 2 ** 3 / 2? A. 4 B. 6 C. 4.0 D. 6.0

D. 6.0

Analyze the following statement: sum = 0 for d in range(0, 10, 0.1): sum += sum + d A. The program has a syntax error because the range function cannot have three arguments. B. The program has a syntax error because the arguments in the range must be integers. C. The program runs in an infinite loop. D. The program runs fine.

B. The program has a syntax error because the arguments in the range must be integers.

Analyze the following code: even = False if even = True: print("It is even!") A. The program has a syntax error in line 1 (even = False) B. The program has a syntax error in line 2 if even = True is not a correct condition. It should be replaced by if even == True: or if even:. C. The program runs, but displays nothing. D. The program runs and displays It is even!.

B. The program has a syntax error in line 2 if even = True is not a correct condition. It should be replaced by if even == True: or if even:.

Analyze the following code: class A: def __init__(self): self.x = 1 self.__y = 1 def getY(self): return self.__y a = A() a.__y = 45 print(a.getX()) A. The program has an error because x is private and cannot be access outside of the class. B. The program has an error because y is private and cannot be access outside of the class. C. The program has an error because you cannot name a variable using __y. D. The program runs fine and prints 1. E. The program runs fine and prints 45.

B. The program has an error because y is private and cannot be access outside of the class.

Analyze the following code: class A: def __init__(self): self.x = 1 self.__y = 1 def getY(self): return self.__y a = A() print(a.__y) A. The program has an error because x is private and cannot be access outside of the class. B. The program has an error because y is private and cannot be access outside of the class. C. The program has an error because you cannot name a variable using __y. D. The program runs fine and prints 1. E. The program runs fine and prints 0.

B. The program has an error because y is private and cannot be access outside of the class.

__________ is to implement one function in the structure chart at a time from the top to the bottom. A. Bottom-up approach B. Top-down approach C. Bottom-up and top-down approach D. Stepwise refinement

B. Top-down approach

Suppose s is "Welcome", what is s.upper()? A. welcome B. WELCOME C. Welcome

B. WELCOME

Suppose list1 is [1, 3, 2, 4, 5, 2, 1, 0], What is list1[:-1]? A. 0 B. [1, 3, 2, 4, 5, 2, 1] C. [1, 3, 2, 4, 5, 2] D. [1, 3, 2, 4, 5, 2, 1, 0]

B. [1, 3, 2, 4, 5, 2, 1]

Suppose list1 is [3, 4, 5, 20, 5, 25, 1, 3], what is list1 after list1.sort()? A. [3, 4, 5, 20, 5, 25, 1, 3] B. [1, 3, 3, 4, 5, 5, 20, 25] C. [25, 20, 5, 5, 4, 3, 3, 1] D. [1, 3, 4, 5, 20, 5, 25, 3]

B. [1, 3, 3, 4, 5, 5, 20, 25]

What will be displayed by the following code? list1 = [1, 3] list2 = list1 list1[0] = 4 print(list2) A. [1, 3] B. [4, 3] C. [1, 4] D. [1, 3, 4]

B. [4, 3]

You can place the line continuation symbol __ at the end of a line to tell the interpreter that the statement is continued on the next line. A. / B. \ C. # D. * E. &

B. \

In the following code, def A: def __init__(self): __a = 1 self.__b = 1 self.__c__ = 1 __d__ = 1 # Other methods omitted Which of the following is a private data field? A. __a B. __b C. __c__ D. __d__

B. __b

random.random() returns ____________. A. a float number i such that 0 < i < 1.0 B. a float number i such that 0 <= i < 1.0 C. a float number i such that 0 <= i <= 1.0 D. a float number i such that 0 < i < 2.0

B. a float number i such that 0 <= i < 1.0

The readlines() method returns a ____________. A. str B. a list of lines C. a list of single characters D. a list of integers

B. a list of lines

Given the following function def nPrint(message, n): while n > 0: print(message) n -= 1 What will be displayed by the call nPrint('a', 4)? A. aaaaa B. aaaa C. aaa D. invalid call E. infinite loop

B. aaaa

Suppose x is 345.3546, what is format(x, "10.3f")? (note b represents a blank space) A. bb345.355 B. bbb345.355 C. bbbb345.355 D. bbb345.354 E. bbbb345.354

B. bbb345.355

What is max(3, 5, 1, 7, 4)? A. 1 B. 3 C. 5 D. 7 E. 4

D. 7

Why do computers use zeros and ones? A. because combinations of zeros and ones can represent any numbers and characters. B. because digital devices have two stable states and it is natural to use one state for 0 and the other for 1. C. because binary numbers are simplest. D. because binary numbers are the bases upon which all other number systems are built.

B. because digital devices have two stable states and it is natural to use one state for 0 and the other for 1.

To bind a canvas with a left mouse click event p, use __________ A. canvas.left(p) B. canvas.bind("<Button-1>", p) C. canvas.bind("Button-1", p) D. canvas.bind(<Button-1>, p)

B. canvas.bind("<Button-1>", p)

To bind a canvas with a mouse entered event p, use __________ A. canvas.entered(p) B. canvas.bind("<Enter>", p) C. canvas.bind("<Entered>", p) D. canvas.bind(<Enter>, p)

B. canvas.bind("<Enter>", p)

How do you draw an arc centered at 100, 100 with radius 20, starting angle 15, ending angle 50, filled with red color on canvas? A. canvas.create_arc(100 - 20, 100 - 20, 100 + 20, 100 + 20, fill = "red", start = 15, extent = 50) B. canvas.create_arc(100 - 20, 100 - 20, 100 + 20, 100 + 20, fill = "red", start = 15, extent = 35) C. canvas.create_arc(100 - 20, 100 - 20, 100 + 20, 100 + 20, filled = "red", start = 15, extent = 50) D. canvas.create_arc(100 - 20, 100 - 20, 100 + 20, 100 + 20, fill = "red", start = 15, end = 50)

B. canvas.create_arc(100 - 20, 100 - 20, 100 + 20, 100 + 20, fill = "red", start = 15, extent = 35)

How do you draw a circle rectangle centered at 100, 100 with radius 100 on canvas? A. canvas.create_oval(100, 100, 100, 100) B. canvas.create_oval(100 - 100, 100 - 100, 100 + 100, 100 + 100) C. canvas.create_oval(100 - 50, 100 - 50, 100 + 50, 100 + 50) D. canvas.create_circle(100 - 100, 100 - 100, 100 + 100, 100 + 100)

B. canvas.create_oval(100 - 100, 100 - 100, 100 + 100, 100 + 100)

An object is an instance of a __________. A. program B. class C. method D. data

B. class

Which option do you use to put the components in a container using the pack manager in the same row? A. component.pack(LEFT) B. component.pack(side = LEFT) C. component.pack(side = "LEFT") D. component.pack("LEFT")

B. component.pack(side = LEFT)

What is the value of times displayed? def main(): myCount = Count() times = 0 for i in range(0, 100): increment(myCount, times) print("myCount.count =", myCount.count, "times =", times) def increment(c, times): c.count += 1 times += 1 class Count: def __init__(self): self.count = 0 main() A. count is 101 times is 0 B. count is 100 times is 0 C. count is 100 times is 100 D. count is 101 times is 101

B. count is 100 times is 0

Invoking the ___________ method converts raw byte data to a string. A. encode() B. decode() C. convert() D. toString()

B. decode()

Which of the following functions cause an error? (multiple) A. int("034") B. eval("034") C. int("3.4") D. eval("3.4")

B. eval("034") C. int("3.4")

_____________ displays a file dialog for saving a file. A. filename = askopenfilename() B. filename = asksaveasfilename() C. filename = openfilename() D. filename = saveasfilename()

B. filename = asksaveasfilename()

What is the type for object 5.6? A. int B. float C. str

B. float

The header of a function consists of ____________. A. function name B. function name and parameter list C. parameter list

B. function name and parameter list

To place a button in a specified row and column in its parent container, use ________. A. pack manager B. grid manager C. place manager D. flow manager

B. grid manager

What will be displayed by after the following loop terminates? number = 25 isPrime = True for i in range(2, number): if number % i == 0: isPrime = False break print("i is", i, "isPrime is", isPrime) A. i is 5 isPrime is True B. i is 5 isPrime is False C. i is 6 isPrime is True D. i is 6 isPrime is False

B. i is 5 isPrime is False

Suppose i is 2 and j is 4, i + j is same as _________. A. i.__add(j) B. i.__add__(j) C. i.__Add(j) D. i.__ADD(j)

B. i.__add__(j)

To open a file c:\scores.txt for reading, use __________. A. infile = open("c:\scores.txt", "r") B. infile = open("c:\\scores.txt", "r") C. infile = open(file = "c:\scores.txt", "r") D. infile = open(file = "c:\\scores.txt", "r")

B. infile = open("c:\\scores.txt", "r")

To read the entire remaining contents of the file as a string from a file object infile, use _________. A. infile.read(2) B. infile.read() C. infile.readline() D. infile.readlines()

B. infile.read()

In Python, a syntax error is detected by the ________ at _________. A. compiler/at compile time B. interpreter/at runtime C. compiler/at runtime D. interpreter/at compile time

B. interpreter/at runtime

To create a label under parent window, use _______. A. label = Label(text = "Welcome to Python") B. label = Label(window, text = "Welcome to Python") C. label = Label(text = "Welcome to Python", fg = " red") D. label = Label(text = "Welcome to Python", fg = " red", bg = "white")

B. label = Label(window, text = "Welcome to Python")

Use the selectionSort function presented in this section to answer this question. What is list1 after executing the following statements? list1 = [3.1, 3.1, 2.5, 6.4] selectionSort(list1) A. list1 is 3.1, 3.1, 2.5, 6.4 B. list1 is 2.5 3.1, 3.1, 6.4 C. list1 is 6.4, 3.1, 3.1, 2.5 D. list1 is 3.1, 2.5, 3.1, 6.4

B. list1 is 2.5 3.1, 3.1, 6.4

To add 5 to the end of list1, use _______. A. list1.add(5) B. list1.append(5) C. list1.addLast(5) D. list1.addEnd(5)

B. list1.append(5)

Assume v1 = IntVar(), how do you create a check button under parent frame1 with variable bound to v1? A. Checkbutton(frame1, text = "Bold", command = processCheckbutton) B. Checkbutton(frame1, text = "Bold", variable = v1.get()) C. Checkbutton(frame1, text = "Bold", variable = v1, command = processCheckbutton) D. Checkbutton(frame1, text = "Bold", variable = v1.set(), command = processCheckbutton)

C. Checkbutton(frame1, text = "Bold", variable = v1, command = processCheckbutton)

What will be displayed by the following code? class Count: def __init__(self, count = 0): self.__count = count c1 = Count(2) c2 = Count(2) print(id(c1) == id(c2), end = " ") s1 = "Good" s2 = "Good" print(id(s1) == id(s2)) A. True False B. True True C. False True D. False False

C. False True

What is "Good".replace("o", "e")? A. God B. Good C. Geed D. Ged E. Good

C. Geed

Given the following four patterns, Pattern A Pattern B Pattern C Pattern D 1 1 2 3 4 5 6 1 1 2 3 4 5 6 1 2 1 2 3 4 5 2 1 1 2 3 4 5 1 2 3 1 2 3 4 3 2 1 1 2 3 4 1 2 3 4 1 2 3 4 3 2 1 1 2 3 1 2 3 4 5 1 2 5 4 3 2 1 1 2 1 2 3 4 5 6 1 6 5 4 3 2 1 1 Which of the pattern is produced by the following code? for i in range(1, 6 + 1): for j in range(6, 0, -1): print(j if j <= i else " ", end = " ") print() A. Pattern A B. Pattern B C. Pattern C D. Pattern D

C. Pattern C

_______ is the code in natural language mixed with some program code. A. Python program B. A Python statement C. Pseudocode D. A flowchart diagram

C. Pseudocode

What will be displayed by the following code? x = 1 def f1(): x = x + 2 print(x) f1() print(x) A. 1 3 B. 3 1 C. The program has a runtime error because x is not defined. D. 1 1 E. 3 3

C. The program has a runtime error because x is not defined.

Analyze the following fragment: sum = d = 0 while d != 10.0: d += 0.1 sum += sum + d A. The program does not run because sum and d are not initialized correctly. B. The program never stops because d is always 0.1 inside the loop. C. The program may not stop because of the phenomenon referred to as numerical inaccuracy for operating with floating-point numbers. D. After the loop, sum is 0 + 0.1 + 0.2 + 0.3 + ... + 1.9

C. The program may not stop because of the phenomenon referred to as numerical inaccuracy for operating with floating-point numbers.

How do you create a text area? A. use Label B. Use Button C. Use Text D. Use Message

C. Use Text

____________ is an operating system. A. Java B. C++ C. Windows XP D. Visual Basic E. Python

C. Windows XP

Suppose list1 = [0.5 * x for x in range(0, 4)], list1 is ________ A. [0, 1, 2, 3] B. [0, 1, 2, 3, 4] C. [0.0, 0.5, 1.0, 1.5] D. [0.0, 0.5, 1.0, 1.5, 2.0]

C. [0.0, 0.5, 1.0, 1.5]

What will be displayed by the following code? def f(i, values = []): values.append(i) return values f(1) f(2) v = f(3) print(v) A. [1] [2] [3] B. [1] [1, 2] [1, 2, 3] C. [1, 2, 3] D. 1 2 3

C. [1, 2, 3]

Suppose list1 is [1, 3, 2], What is list1 * 2? A. [2, 6, 4] B. [1, 3, 2, 1, 3] C. [1, 3, 2, 1, 3, 2] D. [1, 3, 2, 3, 2, 1]

C. [1, 3, 2, 1, 3, 2]

Suppose list1 is [3, 4, 5, 20, 5, 25, 1, 3], what is list1 after list1.pop(1)? A. [3, 4, 5, 20, 5, 25, 1, 3] B. [1, 3, 3, 4, 5, 5, 20, 25] C. [3, 5, 20, 5, 25, 1, 3] D. [1, 3, 4, 5, 20, 5, 25] E. [3, 1, 25, 5, 20, 5, 4]

C. [3, 5, 20, 5, 25, 1, 3]

What will be displayed by the following code? def f(values): values[0] = 44 v = [1, 2, 3] f(v) print(v) A. [1, 44] B. [1, 2, 3, 44] C. [44, 2, 3] D. [1, 2, 3]

C. [44, 2, 3]

What is min("Programming is fun")? A. P B. r C. a blank space character D. u E. n

C. a blank space character

How do you draw a polygon consisting of points (30, 40), (50, 50), (10, 100) filled with red color? A. canvas.create_poly(30, 40, 50, 50, 10, 100, fill = "red") B. canvas.create_polygon(30, 40, 50, 50, 10, 100, filled = "red") C. canvas.create_polygon(30, 40, 50, 50, 10, 100, fill = "red") D. canvas.create_polygon((30, 40), (50, 50), (10, 100), fill = "red")

C. canvas.create_polygon(30, 40, 50, 50, 10, 100, fill = "red")

The keyword __________ is required to define a class. A. def B. return C. class D. All of the above.

C. class

Which of the following function headers is correct? A. def f(a = 1, b): B. def f(a = 1, b, c = 2): C. def f(a = 1, b = 1, c = 2): D. def f(a = 1, b = 1, c = 2, d):

C. def f(a = 1, b = 1, c = 2):

Which function do you use to write data to perform binary output? A. write B. output C. dump D. send

C. dump

How do you create a frame? A. frame = newWindow() B. frame = Window() C. frame = Frame() D. frame = Tk()

C. frame = Frame()

Suppose the input for number is 9. What will be displayed by the following program? number = eval(input("Enter an integer: ")) isPrime = True for i in range(2, number): if number % i == 0: isPrime = False print("i is", i) if isPrime: print(number, "is prime") break else: print(number, "is not prime") A. i is 3 followed by 9 is prime B. i is 3 followed by 9 is not prime C. i is 2 followed by 9 is prime D. i is 2 followed by 9 is not prime

C. i is 2 followed by 9 is prime

Suppose isPrime is a boolean variable, which of the following is the correct and best statement for testing if isPrime is true. A. if isPrime = True: B. if isPrime == True: C. if isPrime: D. if not isPrime = False: E. if not isPrime == False:

C. if isPrime:

Which of the following code displays the area of a circle if the radius is positive. A. if radius != 0: print(radius * radius * 3.14159) B. if radius >= 0: print(radius * radius * 3.14159) C. if radius > 0: print(radius * radius * 3.14159) D. if radius <= 0: print(radius * radius * 3.14159)

C. if radius > 0: print(radius * radius * 3.14159)

To create an image, use ______________________. A. image = PhotoImage(imagefilename) B. image = Image(file = imagefilename) C. image = PhotoImage(file = imagefilename) D. image = PhotoImage(imagefilename)

C. image = PhotoImage(file = imagefilename)

To read the next line of the file from a file object infile, use _________. A. infile.read(2) B. infile.read() C. infile.readline() D. infile.readlines()

C. infile.readline()

The following code displays ___________. temperature = 50 if temperature >= 100: print("too hot") elif temperature <= 40: print("too cold") else: print("just right") A. too hot B. too cold C. just right D. too hot too cold just right

C. just right

Which function do you use to read data using binary input? A. read B. input C. load D. receive

C. load

The speed of the CPU may be measured in __________. (multiple) A. megabytes B. gigabytes C. megahertz D. gigahertz

C. megahertz D. gigahertz

What is the number of iterations in the following loop: for i in range(1, n): # iteration A. 2*n B. n C. n - 1 D. n + 1

C. n - 1

The ______ function can be used to check if a file f exists. A. os.path.isFile(f) B. os.path.exists(f) C. os.path.isfile(f) D. os.isFile(f)

C. os.path.isfile(f)

Suppose number contains integer value 4, which of the following statement is correct? (multiple) A. print(format(number, "2d"), format(number ** 1.5, "4d")) B. print(format(number, "2d"), format(number ** 1.5, "4.2d")) C. print(format(number, "2d"), format(number ** 1.5, "4.2f")) D. print(format(number, "2f"), format(number ** 1.5, "4.2f")) E. print(format(number, "2.1f"), format(number ** 1.5, "4.2f"))

C. print(format(number, "2d"), format(number ** 1.5, "4.2f")) D. print(format(number, "2f"), format(number ** 1.5, "4.2f")) E. print(format(number, "2.1f"), format(number ** 1.5, "4.2f"))

To start Python from the command prompt, use the command ________. A. execute python B. run python C. python D. go python

C. python

To run python script file named t.py, use the command ________. A. execute python t.py B. run python t.py C. python t.py D. go python t.py

C. python t.py

To shuffle list1, use _______. A. list1.shuffle() B. shuffle(list1) C. random.shuffle(list1) D. random.shuffleList(list1)

C. random.shuffle(list1)

Using a grid manager, you can use the option _________ to place a component in multiple rows and columns. (multiple) A. row B. column C. rowspan D. columnspan

C. rowspan D. columnspan

Given a string s = "Welcome", which of the following code is incorrect? A. print(s[0]) B. print(s.lower()) C. s[1] = 'r' D. print(s.strip())

C. s[1] = 'r'

In Python, a string literal is enclosed in __________. (multiple) A. parentheses B. brackets C. single-quotes D. double-quotes E. braces

C. single-quotes D. double-quotes

Suppose s = "Welcome", what is type(s)? A. int B. float C. str D. String

C. str

The __________ function immediately terminates the program. A. sys.terminate() B. sys.halt() C. sys.exit() D. sys.stop()

C. sys.exit()

To display an error dialog named "Variable is not assigned", use __________ A. tkinter.messagebox.showinfo("showinfo", "Variable is not assigned") B. tkinter.messagebox.showwarning("showwarning", "Variable is not assigned") C. tkinter.messagebox.showerror("showerror", "Variable is not assigned") D. tkinter.messagebox.askyesno("ashyesno", "Variable is not assigned")

C. tkinter.messagebox.showerror("showerror", "Variable is not assigned")

To undo the last turtle action, use _________. A. turtle.rollback() B. turtle.redo() C. turtle.undo() D. turtle.remove()

C. turtle.undo()

Assume v1 = IntVar(), how do you set a new value 5 to v1. A. v1 = 5 B. v1.setValue(5) C. v1.set(5) D. v1.get(5)

C. v1.set(5)

To add a menubar, use __________ A. window.configure(menu = menubar) B. window.config(menubar) C. window.config(menu = menubar) D. window.configure(menubar)

C. window.config(menu = menubar)

Given |x - 2| <= 4, Which of the following is true? A. x - 2 <= 4 and x - 2 >= 4 B. x - 2 <= 4 and x - 2 > -4 C. x - 2 <= 4 and x - 2 >= -4 D. x - 2 <= 4 or x - 2 >= -4

C. x - 2 <= 4 and x - 2 >= -4

Given the declaration x = Circle(), which of the following statement is most accurate. A. x contains an int value. B. x contains an object of the Circle type. C. x contains a reference to a Circle object. D. You can assign an int value to x.

C. x contains a reference to a Circle object.

What is x after the following statements? x = 1 y = 2 x *= y + 1 A. x is 1 B. x is 2 C. x is 3 D. x is 4

C. x is 3

2 ** 3.0 evaluates to __________. A. 9 B. 8 C. 9.0 D. 8.0

D. 8.0

The Unicode of 'a' is 97. What is the Unicode for 'c'? A. 96 B. 97 C. 98 D. 99

D. 99

Which of the following loops prints "Welcome to Python" 10 times? A: for count in range(1, 10): print("Welcome to Python") B: for count in range(0, 10): print("Welcome to Python") C: for count in range(1, 11): print("Welcome to Python") D: for count in range(1, 12): print("Welcome to Python") A. BD B. ABC C. AC D. BC E. AB

D. BC

Given the following function def nPrint(message, n): while n > 0: print(message) n -= 1 What will be displayed by the call nPrint('a', 4)? A. aaaaa B. aaaa C. aaa D. invalid call E. infinite loop

E. infinite loop

What is "Programming is fun"[1:1]? A. P B. r C. Pr D. '' E. incorrect expression

D. ''

Suppose list1 is [1, 3, 2, 4, 5, 2, 1, 0], What is list1[-1]? A. 3 B. 5 C. 1 D. 0

D. 0

The function range(5) return a sequence ______________. A. 1, 2, 3, 4, 5 B. 0, 1, 2, 3, 4, 5 C. 1, 2, 3, 4 D. 0, 1, 2, 3, 4

D. 0, 1, 2, 3, 4

What is math.sin(math.pi / 6)? A. 1.0 B. 1.3434343 C. 3.141592653589793 D. 0.5

D. 0.5

Suppose list1 is [3, 4, 5, 20, 5, 25, 1, 3], what is list1.count(5)? A. 0 B. 4 C. 1 D. 2

D. 2

Suppose list1 is [3, 4, 5, 20, 5, 25, 1, 3], what is list1.index(5)? A. 0 B. 4 C. 1 D. 2

D. 2

What will be displayed by the following code? x, y = 1, 2 x, y = y, x print(x, y) A. 1 1 B. 2 2 C. 1 2 D. 2 1

D. 2 1

What is the output for y? y = 0 for i in range(0, 10, 2): y += i print(y) A. 9 B. 10 C. 11 D. 20

D. 20

Suppose list1 is [3, 4, 5, 20, 5, 25, 1, 3], what is max(list1)? A. 5 B. 4 C. 8 D. 25 E. 1

D. 25

Suppose x is 1. What is x after x += 2? A. 0 B. 1 C. 2 D. 3 E. 4

D. 3

What will be displayed by the following code? x = 1 x = 2 * x + 1 print(x) A. 0 B. 1 C. 2 D. 3 E. 4

D. 3

What will be displayed by the following code? def f1(x = 1, y = 2): return x + y, x - y x, y = f1(y = 2, x = 1) print(x, y) A. 1 3 B. 3 1 C. The program has a runtime error because the function returns the multiple values D. 3 -1 E. -1 3

D. 3 -1

What will be displayed by the following code? def f1(x = 1, y = 2): x = x + y y += 1 print(x, y) f1(2, 1) A. 1 3 B. 2 3 C. The program has a runtime error because x and y are not defined. D. 3 2 E. 3 3

D. 3 2

What will be displayed by the following code? def f(value, values): v = 1 values[0] = 44 t = 3 v = [1, 2, 3] f(t, v) print(t, v[0]) A. 1 1 B. 1 44 C. 3 1 D. 3 44

D. 3 44

What will be displayed by the following code? x = 1 x = x + 2.5 print(x) A. 1 B. 2 C. 3 D. 3.5 E. The statements are illegal

D. 3.5

Which of the following expression results in a value 1? A. 2 % 1 B. 15 % 4 C. 25 % 5 D. 37 % 6

D. 37 % 6

24 % 5 is _____ A. 1 B. 2 C. 3 D. 4 E. 0

D. 4

Given a string s = "Programming is fun", what is s.find('ram')? A. 1 B. 2 C. 3 D. 4 E. -1

D. 4

What is len("Good")? A. 1 B. 2 C. 3 D. 4 E. -1

D. 4

What is round(3.52)? A. 3.5 B. 3 C. 5 D. 4 E. 3.0

D. 4

How many times is the print statement executed? for i in range(10): for j in range(i): print(i * j) A. 100 B. 20 C. 10 D. 45

D. 45

Analyze the following code: Code 1: if number % 2 == 0: even = True else: even = False Code 2: even = number % 2 == 0 A. Code 1 has compile errors. B. Code 2 has compile errors. C. Both Code 1 and Code 2 have compile errors. D. Both Code 1 and Code 2 are correct, but Code 2 is better.

D. Both Code 1 and Code 2 are correct, but Code 2 is better.

To create a button under parent window with command processButton, use _______. A. Button(text = "OK", fg = "red", command = processButton) B. Button(window, text = "OK", fg = "red") C. Button(window, text = "OK", fg = "red") D. Button(window, text = "OK", command = processButton)

D. Button(window, text = "OK", command = processButton)

Python was created by ____________. A. James Gosling B. Bill Gates C. Steve Jobs D. Guido van Rossum E. Google

D. Guido van Rossum

Which of the following code is correct? I: print("Programming is fun") print("Python") print("Computer Science") II: print("Programming is fun") print("Python") print("Computer Science") III: print("Programming is fun") print("Python") print("Computer Science") IV: print("Programming is fun") print("Python") print("Computer Science") A. I B. II C. III D. IV

D. IV

The expression "Good " + 1 + 2 + 3 evaluates to ________. A. Good123 B. Good6 C. Good 123 D. Illegal expression

D. Illegal expression

A function with no return statement returns ______. A. void B. nothing C. 0 D. None

D. None

What is "Programming is fun"[:-1]? A. Programming B. rogramming is fun C. Programming is f D. Programming is fu E. Programming is

D. Programming is fu

Assume v1 = IntVar(), how do you create a radio button under parent frame1 with variable bound to v1 and value 1? A. Checkbutton(frame1, text = "Bold", command = processCheckbutton) B. Checkbutton(frame1, text = "Bold", variable = v1.get()) C. Checkbutton(frame1, text = "Bold", variable = v1, command = processCheckbutton) D. Radiobutton(frame1, text = "Yellow", bg = "yellow", variable = v1, value = 1, command = processRadiobutton)

D. Radiobutton(frame1, text = "Yellow", bg = "yellow", variable = v1, value = 1, command = processRadiobutton)

Analyze the following code: class A: def __init__(self, s): self.s = s def print(self): print(self.s) a = A() a.print() A. The program has an error because class A does not have a constructor. B. The program has an error because s is not defined in print(s). C. The program runs fine and prints nothing. D. The program has an error because the constructor is invoked without an argument.

D. The program has an error because the constructor is invoked without an argument.

Analyze the following code: class A: def __init__(self): self.x = 1 self.__y = 1 def getY(self): return self.__y a = A() print(a.x) A. The program has an error because x is private and cannot be access outside of the class. B. The program has an error because y is private and cannot be access outside of the class. C. The program has an error because you cannot name a variable using __y. D. The program runs fine and prints 1. E. The program runs fine and prints 0.

D. The program runs fine and prints 1.

Analyze the following code: class A: def __init__(self, s): self.s = s def print(self): print(s) a = A("Welcome") a.print() A. The program has an error because class A does not have a constructor. B. The program has an error because class A should have a print method with signature print(self, s). C. The program has an error because class A should have a print method with signature print(s). D. The program would run if you change print(s) to print(self.s).

D. The program would run if you change print(s) to print(self.s).

Given a string s = "Programming is fun", what is s.endswith('fun')? A. 0 B. 1 C. -1 D. True E. False

D. True

Given a string s = "Programming is fun", what is s.startswith('Program')? A. 0 B. 1 C. -1 D. True E. False

D. True

How do you create a GUI component for displaying multiple-lines of text? A. use Label B. Use Button C. Use Text D. Use Message

D. Use Message

What will be displayed by the following code? ? (note ? represents a blank space) print(format("Welcome", "10s"), end = '#') print(format(111, "4d"), end = '#') print(format(924.656, "3.2f")) A. ???Welcome#?111#924.66 B. Welcome#111#924.66 C. Welcome#111#.66 D. Welcome???#?111#924.66

D. Welcome???#?111#924.66

A variable defined inside a function is referred to as __________. A. a global variable B. a function variable C. a block variable D. a local variable

D. a local variable

How do you draw a red line from 100, 100 to 400, 500? A. canvas.create_line(100, 100, 100, 500, fill = "red") B. canvas.create_line(100, 100, 400, 100, fill = "Red") C. canvas.create_line(100, 100, 400, 500, filled = "red") D. canvas.create_line(100, 100, 400, 500, fill = "red")

D. canvas.create_line(100, 100, 400, 500, fill = "red")

How do you draw a rectangle centered at 100, 100 with width 100 and height 100 on canvas? A. canvas.create_rect(100, 100, 100, 100) B. canvas.create_rectangle(100, 100, 100, 100) C. canvas.create_rect(100 - 50, 100 - 50, 100 + 50, 100 + 50) D. canvas.create_rectangle(100 - 50, 100 - 50, 100 + 50, 100 + 50)

D. canvas.create_rectangle(100 - 50, 100 - 50, 100 + 50, 100 + 50)

What will be displayed by after the following loop terminates? number = 25 isPrime = True i = 2 while i < number and isPrime: if number % i == 0: isPrime = False i += 1 print("i is", i, "isPrime is", isPrime) A. i is 5 isPrime is True B. i is 5 isPrime is False C. i is 6 isPrime is True D. i is 6 isPrime is False

D. i is 6 isPrime is False

To read the remaining lines of the file from a file object infile, use _________. A. infile.read(2) B. infile.read() C. infile.readline() D. infile.readlines()

D. infile.readlines()

For the binarySearch function in Section 10.10.2, what is low and high after the first iteration of the while loop when invoking binarySearch([1, 4, 6, 8, 10, 15, 20], 11)? A. low is 0 and high is 6 B. low is 0 and high is 3 C. low is 3 and high is 6 D. low is 4 and high is 6 E. low is 0 and high is 5

D. low is 4 and high is 6

To display a popup menu, use __________ A. menu.display() B. menu.post() C. menu.display(300, 300) D. menu.post(300, 300)

D. menu.post(300, 300)

Suppose x = 1, y = -1, and z = 1. What will be displayed by the following statement? if x > 0: if y > 0: print("x > 0 and y > 0") elif z > 0: print("x < 0 and z > 0") A. x > 0 and y > 0 B. x < 0 and z > 0 C. x < 0 and z < 0 D. nothing displayed

D. nothing displayed

Suppose i is an int type variable. Which of the following statements display the character whose Unicode is stored in variable i? A. print(i) B. print(str(i)) C. print(int(i)) D. print(chr(i))

D. print(chr(i))

Consider the following incomplete code: def f(number): # Missing function body print(f(5)) The missing function body should be ________. A. return "number" B. print(number) C. print("number") D. return number

D. return number

Which of the following functions return 4. A. int(3.4) B. int(3.9) C. round(3.4) D. round(3.9)

D. round(3.9)

To add number to sum, you write (Note: Python is case-sensitive) (multiple) A. number += sum B. number = sum + number C. sum = Number + sum D. sum += number E. sum = sum + number

D. sum += number E. sum = sum + number

To display an input dialog named "Is this an integer?", use __________ A. tkinter.messagebox.showinfo("showinfo", "Is this an integer?") B. tkinter.messagebox.showwarning("showwarning", "Is this an integer?") C. tkinter.messagebox.showerror("showerror", "Is this an integer?") D. tkinter.messagebox.askyesno("ashyesno", "Is this an integer?")

D. tkinter.messagebox.askyesno("ashyesno", "Is this an integer?")

To draw a circle of diameter 10 with filled color red, use _________. A. turtle.circle(5, "red") B. turtle.circle(10, "red") C. turtle.dot(5, "red") D. turtle.dot(10, "red")

D. turtle.dot(10, "red")

To show the current location and direction of the turtle object, use ___________. A. turtle.show() B. turtle.showLocation() C. turtle.showDirection() D. turtle.showturtle() E. turtle.showTurtle()

D. turtle.showturtle()

What is max("Programming is fun")? A. P B. r C. a blank space character D. u E. n

D. u

Suppose s is "\t\tWelcome\n", what is s.strip()? A. \t\tWelcome\n B. \t\tWelcome\n C. \t\tWELCOME\n D. welcome

D. welcome

How do you create a window? A. window = newWindow() B. window = Window() C. window = Frame() D. window = Tk()

D. window = Tk()

Assume x = 4 and y = 5, Which of the following is true? A. not (x == 4) B. x != 4 C. x == 5 D. x != 5

D. x != 5

What is x after the following statements? x = 2 y = 1 x *= y + 1 A. x is 1. B. x is 2. C. x is 3. D. x is 4.

D. x is 4.

What is displayed when the following program is run? try: list = 10 * [0] x = list[10] print("Done") except IndexError: print("Index out of bound") else: print("Nothing is wrong") finally: print("Finally we are here") A. "Done" followed by "Nothing is wrong" B. "Done" followed by "Nothing is wrong" followed by "Finally we are here" C. "Index out of bound" followed by "Nothing is wrong" followed by "Finally we are here" D. "Nothing is wrong" followed by "Finally we are here" E. "Index out of bound" followed by "Finally we are here"

E. "Index out of bound" followed by "Finally we are here"

Given a string s = "Programming is fun", what is s.find('rom')? A. 1 B. 2 C. 3 D. 4 E. -1

E. -1

25 % 1 is _____ A. 1 B. 2 C. 3 D. 4 E. 0

E. 0

Use the selectionSort function presented in this section to answer this question. Assume lst is [3.1, 3.1, 2.5, 6.4, 2.1], what is the content of list after the first iteration of the outer loop in the function? A. 3.1, 3.1, 2.5, 6.4, 2.1 B. 2.5, 3.1, 3.1, 6.4, 2.1 C. 2.1, 2.5, 3.1, 3.1, 6.4 D. 3.1, 3.1, 2.5, 2.1, 6.4 E. 2.1, 3.1, 2.5, 6.4, 3.1

E. 2.1, 3.1, 2.5, 6.4, 3.1

What will be displayed by the following code? def f1(x = 1, y = 2): x = x + y y += 1 print(x, y) f1() A. 1 3 B. 3 1 C. The program has a runtime error because x and y are not defined. D. 1 1 E. 3 3

E. 3 3

What will be displayed by the following code? def f1(x = 1, y = 2): x = x + y y += 1 print(x, y) f1(y = 2, x = 1) A. 1 3 B. 2 3 C. The program has a runtime error because x and y are not defined. D. 3 2 E. 3 3

E. 3 3

What will be displayed by the following code? x = 1 def f1(): global x x = x + 2 print(x) f1() print(x) A. 1 3 B. 3 1 C. The program has a runtime error because x is not defined. D. 1 1 E. 3 3

E. 3 3

What is the output for y? y = 0 for i in range(0, 10): y += i print(y) A. 10 B. 11 C. 12 D. 13 E. 45

E. 45

What is the value of i printed? j = i = 1 i += j + j * 5 print("What is i?", i) A. 0 B. 1 C. 5 D. 6 E. 7

E. 7

What is round(7.5)? A. 4 B. 5 C. 6 D. 7 E. 8

E. 8

Which of the following operators are right-associative. A. * B. + C. % D. and E. =

E. =

Suppose you write the code to display "Cannot get a driver's license" if age is less than 16 and "Can get a driver's license" if age is greater than or equal to 16. Which of the following code is correct? I: if age < 16: print("Cannot get a driver's license") if age >= 16: print("Can get a driver's license") II: if age < 16: print("Cannot get a driver's license") else: print("Can get a driver's license") III: if age < 16: print("Cannot get a driver's license") elif age >= 16: print("Can get a driver's license") IV: if age < 16: print("Cannot get a driver's license") elif age == 16: print("Can get a driver's license") elif age > 16: print("Can get a driver's license") A. I and II B. II and III C. I, II, and III D. III and IV E. All correct

E. All correct

Analyze the following code fragments that assign a boolean value to the variable even. Code 1: if number % 2 == 0: even = True else: even = False Code 2: even = True if number % 2 == 0 else False Code 3: even = number % 2 == 0 A. Code 2 has a syntax error, because you cannot have True and False literals in the conditional expression. B. Code 3 has a syntax error, because you attempt to assign number to even. C. All three are correct, but Code 1 is preferred. D. All three are correct, but Code 2 is preferred. E. All three are correct, but Code 3 is preferred.

E. All three are correct, but Code 3 is preferred.

Given a string s = "Programming is fun", what is s.endswith('m')? A. 0 B. 1 C. -1 D. True E. False

E. False

Given a string s = "Programming is fun", what is s.startswith('m')? A. 0 B. 1 C. -1 D. True E. False

E. False

Analyze the following code: class A: def __init__(self): self.x = 1 self.__y = 1 def getY(self): return self.__y a = A() a.x = 45 print(a.x) A. The program has an error because x is private and cannot be access outside of the class. B. The program has an error because y is private and cannot be access outside of the class. C. The program has an error because you cannot name a variable using __y. D. The program runs fine and prints 1. E. The program runs fine and prints 45.

E. The program runs fine and prints 45.

Analyze the following code: class A: def __init__(self, s = "Welcome"): self.s = s def print(self): print(self.s) a = A() a.print() A. The program has an error because class A does not have a constructor. B. The program has an error because s is not defined in print(s). C. The program runs fine and prints nothing. D. The program has an error because the constructor is invoked without an argument. E. The program runs fine and prints Welcome.

E. The program runs fine and prints Welcome.

If you enter 1 2 3 in one line, when you run this program, what will happen? print("Enter three numbers: ") number1 = eval(input()) number2 = eval(input()) number3 = eval(input()) # Compute average average = (number1 + number2 + number3) / 3 # Display result print(average) A. The program runs correctly and displays 1.0 B. The program runs correctly and displays 2.0 C. The program runs correctly and displays 3.0 D. The program runs correctly and displays 4.0 E. The program will have a runtime error on the input.

E. The program will have a runtime error on the input.

Suppose list1 is [3, 4, 5, 20, 5, 25, 1, 3], what is list1 after list1.reverse()? A. [3, 4, 5, 20, 5, 25, 1, 3] B. [1, 3, 3, 4, 5, 5, 20, 25] C. [25, 20, 5, 5, 4, 3, 3, 1] D. [1, 3, 4, 5, 20, 5, 25, 3] E. [3, 1, 25, 5, 20, 5, 4, 3]

E. [3, 1, 25, 5, 20, 5, 4, 3]

To bind a canvas with a right mouse click event p, use __________ A. canvas.left(p) B. canvas.bind("<Button-1>", p) C. canvas.bind("Button-1", p) D. canvas.bind(<Button-1>, p) E. canvas.bind("<Button-3>", p)

E. canvas.bind("<Button-3>", p)

True or False: An identifier can contain digits, but cannot start with a digit

True

True or False: An identifier cannot be a keyword

True

True or False: Python is case-sensitive.

True

True or False: Python syntax is case-sensitive.

True

True or False: The "Slice" we used with strings can be used with list with the same results except instead of characters, it returns elements in the list.

True

True or False: pow(a, b) is the same as a ** b

True

Given Stuff = [40, 30, 50, 30, 90, 60], what is returned Stuff.count(30) a. 6 b. 1 c. 30 d. 3 e. 2 f. 0 g. 20

e. 2

A computer's _______ is volatile; that is, any information stored in it is lost when the system's power is turned off. a. floppy disk b. hard disk c. flash stick d. CD-ROM e. memory

e. memory


Conjuntos de estudio relacionados

Final exam review HSC3211: exam 1, 2, and 3

View Set

Chapter 14: Disorders Common Among Children and Adolescents

View Set

Final Exam - Hawaii Life and Health

View Set

Developmental Concepts - Peds Module 4

View Set