Intro to Python- CS 1064 Final Exam Review (Quick Checks)

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

A polyline is a closed shape. A) True B) False

B) False

The if clause in a comprehension is optional. A) True B) False

A) True

What is the result of the expression math.floor(12.843)? A) 0 B) 10 C) 12 D) 13

C) 12

The valid indexes of a tuple run from 0 to one less than the length of the tuple. A) True B) False

A) True

Which of the following identifiers follows the naming convention for a Python constant? A) MAX_PENALTIES B) MAXPENALTIES C) maxPenalties D) Max_Penalties

A) MAX_PENALTIES

The best way to read a file line by line is to use a for loop to iterate over the file object itself. A) True B) False

A) True

When drawing a polygon, the order in which the vertices are listed may matter. A) True B) False

A) True

Whether text is displayed in bold or italic type is specified in the font descriptor. A) True B) False

A) True

The optional argument called mask is used to specify a character that will be displayed in a Text widget instead of the actual characters. A) True B) False

B) False

The pass statement is useless. A) True B) False

B) False

The string 'i prefer pi' would be considered a palindrome by the original version of the palindromes program. A) True B) False

B) False

The write method adds a newline character to the end of the output. A) True B) False

B) False (You can add newline characters to the output wherever appropriate)

After a function finishes executing, control returns to the place the function was called. A) True B) False

A) True

Which of the following string literals is NOT valid? A) ""\n"" B) '"' C) '\n' D) "\"\n"

A) ""\n""

Which Python function can be used to call a method of a superclass? A) super B) self C) my D) parent

A) super

EXAMPLE: THE HIGH-LOW GAME section

Answers are based off of this section (week of 2/8)

EXAMPLE: BANK ACCOUNT section

Answers are based on info in this section (go to week of 3/29)

If the variable str refers to the string 'ABC123XYZ', what does the expression str[3:7] produce? A) 'C123' B) '123X' C) '123XY' D) 'C123X'

B) '123X'

If the variable machine refers to the string 'computer', what does the expression machine[0:len(machine):2] produce? A) 'uter' B) 'cmue' C) 'comp' D) 'optr'

B) 'cmue'. (The slice extracts every other character in the entire string.)

The data science process is linear. A) True B) False

B) False

What set is stored in set3 by the following code? set1 = {1, 2, 3, 4, 5} set2 = {3, 4, 5, 6, 7, 8, 9} set3 = set1 | set2 A) {1, 2} B) {1, 2, 3, 4, 5, 6, 7, 8, 9} C) {6, 7, 8, 9} D) {3, 4, 5}

B) {1, 2, 3, 4, 5, 6, 7, 8, 9}. (the operation produces the union of both sets)

Which of the following hex strings represents the color white? A) '#640000' B) '#646464' C) '#000000' D) '#FFFFFF'

D) '#FFFFFF'

Which of the following conclusions is NOT true when using relational operators to compare character strings? A) 'able' comes before 'baker' B) 'moon' comes before 'moonwalk' C) 'ultrasonic' comes before 'ultraviolet' D) 'fantastic' comes before 'Great'

D) 'fantastic' comes before 'Great'. (All uppercase characters come before all lowercase characters, so 'G' comes before 'f'.)

What operator is used to perform string concatenation in Python? A) * B) & C) @ D) +

D) +

What output would be produced when the following code is executed? state = 'Mississippi' print(state.replace('is', 'was')) A) Mwaswasippi B) Mwasswasswaspi C) Mwassissippi D) Mwasswassippi

D) Mwasswassippi (Each occurrence of the substring is replaced)

What is the output of the following code? die = Die(20) die.roll() die.roll() print(die.value) A) 0 B) 1 C) 20 D) A random number between 0 and 19. E) A random number between 1 and 20.

E) A random number between 1 and 20

A cooperating group of radio buttons is determined by the variable each button updates. A) True B) False

True

GUI Widgets Overview section

Refer to this section for term matching (week of 4/19)

Which of the following is NOT true regarding the return statement? A) The last statement in a function must be a return statement. B) The keyword return is usually followed by an expression. C) When a return statement executes, the function stops executing immediately. D) A function can have more than one return statement.

A) The last statement in a function must be a return statement

A Button can display text and an image at the same time. A) True B) False

A) True

A character string can be used as the condition of an if statement. A) True B) False

A) True

A dash pattern of (8, 3) specifies a series of 8-pixel line segments separated by a 3-pixel gap. A) True B) False

A) True

A dictionary is designed for efficient value retrieval. A) True B) False

A) True

A example of a ragged list is a two-dimensional list where each row has a different number of columns. A) True B) False

A) True

A file chooser is a specialized dialog box for selecting files in a directory structure. A) True B) False

A) True

A for loop can be used to compute the sum of all values in a list. A) True B) False

A) True

A for loop is a good way to access each character in a string. A) True B) False

A) True

A function can return a boolean result. A) True B) False

A) True

A function parameter ceases to exist when the function returns to the caller. A) True B) False

A) True

Python uses the Unicode character set to represent characters. A) True B) False

A) True

Swapping two elements in a list requires three assignment statements. A) True B) False

A) True

The Internet of Things is made up of a growing number of devices that collect and transfer data over the Internet without human involvement. A) True B) False

A) True

The Python shell has an integrated help system. A) True B) False

A) True

The askcolor method returns a tuple that specifies the color in two ways. A) True B) False

A) True

The open function can be used to open an input file or create an output file. A) True B) False

A) True

The parameters to the create_rectangle method represent the upper left corner and lower right corner of the rectangle. A) True B) False

A) True

The pass statement has no effect on the program state. A) True B) False

A) True

The result of a comprehension could always be created using more verbose code. A) True B) False

A) True

The result of a relational operator can be assigned to a variable. A) True B) False

A) True

Deriving one class from another establishes what kind of relationship between the two classes? A) is-a B) uses C) aggregation D) has-a

A) is-a

Computing the wrong answer is an example of what kind of error? A) logic error B) runtime error C) interface error D) syntax error

A) logic error

A Python program must be enclosed in curly braces { } to be executed. A) True B) False

B) False

A program that runs without generating a runtime error will produce correct results. A) True B) False

B) False

A turtle draws a filled circle using the fill_circle command. A) True B) False

B) False

By default, rectangles and ovals drawn on a Canvas are filled with black. A) True B) False

B) False

Constants automatically convert between units of measure. A) True B) False

B) False

Each check button in a Python program must have its own event handler function. A) True B) False

B) False

Functions of the math module do not have to be imported. A) True B) False

B) False

If a == b is true, then a is b will also be true. A) True B) False

B) False

The continue statement must be executed after a break statement is executed. A) True B) False

B) False

The default anchor point for text on a Canvas is the northwest (upper left) corner of the text. A) True B) False

B) False

The event handler function for a Button must be called handleButton. A) True B) False

B) False

The from clause of an import statement lets you define an alias for a module or function. A) True B) False

B) False

The function askopenfilename returns a file object. A) True B) False

B) False

Using components from the Python Standard Library is a rare occurrence. A) True B) False

B) False

The results computed by the standard_deviation program are written out to text data file. A) True B) False

B) False. (The results are only printed to standard console output window.)

Which way would the turtle be facing after executing the command turtle.setheading(135)? A) down and left (southwest) B) up and left (northwest) C) left (west) D) right (east) E) down and right (southeast) F) up and right (northeast)

B) up and left (northwest). (The heading angle is based on 0 degrees, which is to the right (east).)

Given the following line of code, which list is produced by the expression values[3:8]? values = [79, 40, 18, 32, 95, 66, 58, 81, 20, 62] A) [18 32, 95, 66, 58, 81] B) [32, 95, 66, 58, 81, 20] C) [32, 95, 66, 58, 81] D) [18, 32, 95, 66, 58, 81, 20]

C) [32, 95, 66, 58, 81]

What does list contain after the following code is executed? list = [82, 27, 66, 18, 40, 93, 85, 29] list.append(50) list.insert(3, 99) list.pop() A) [82, 27, 99, 66, 18, 40, 93, 85, 29] B) [27, 66, 99, 18, 40, 93, 85, 29, 50] C) [82, 27, 66, 99, 18, 40, 93, 85, 29] D) [50, 82, 27, 99, 66, 18, 40, 93, 85]

C) [82, 27, 66, 99, 18, 40, 93, 85, 29, 50]. (The call to pop removes the item that was appended.)

Which direction would the following arc "point"? That is, where is the center point of the oval relative to the arc?canvas.create_arc(150, 250, 250, 400, start=160, extent=40) A) up B) down C) right D) left

C) right

What value will the variable stuff hold after the following code is executed? state = 'Mississippi' stuff = {ch.lower() for ch in state if ch != 'i'} A) ['M', 'i', 's', 's', 'i', 's', 's', 'i', 'p', 'p', 'i'] B) {'m', 'i', 's', 'p'} C) {'m', 's', 'p'} D) ['m', 's', 's', 's', 's', 'p', 'p']

C) {'m', 's', 'p'}. (It's a set containing the unique lowercase letters in the string except for 'i'.)

The expression random.randrange(30) will produce a value in what range? A) 1 to 29 B) 1 to 30 C) 0 to 30 D) 0 to 29

D) 0 to 29. (A call to randrange(N) returns a value in the range 0 to N-1)

Which of the following is NOT an arc type for a Tkinter Canvas? A) PIESLICE B) ARC C) CHORD D) WEDGE

D) WEDGE

What set is stored in set3 by the following code? set1 = {1, 2, 3, 4, 5} set2 = {3, 4, 5, 6, 7, 8, 9} set3 = set1 & set2 A) {6, 7, 8, 9} B) {1, 2} C) {1, 2, 3, 4, 5, 6, 7, 8, 9} D) {3, 4, 5}

D) {3, 4, 5}. (The operation produces the intersection of the two sets.)

Given the following line of code, which expression would produce the substring 'snapper'? young = 'whippersnapper' A) young[7:14] B) young[7:] C) young[-7:] D) young[7:len(young)] E) All of the above. F) None of the above.

E) All of the above

ALGORITHIMS section

This quick check is matching- go to week of 2/1 and go to algorithms section

Which of the following is a relational operator? A) not B) <= C) / D) and

B) <=

If the value of num is 7 and the value of max is 10, what is the value of num after the following statement is executed? num = max if max < num else max - num A) 3 B) 4 C) 7 D) 10

A) 3. (The difference between max and num is assigned to num because the condition is false)

What output is produced by the following code?print(15 + 30) A) 45 B) 45.0 C) "1530" D) 1530

A) 45

What is a docstring? A) A character string used as a comment in a program. B) A series of characters concatenated into a single line of text. C) A character string used to debug a program. D) A series of documents concatenated into a single document.

A) A character string used as a comment in a program

What causes an infinite loop? A) A loop condition that is never false. B) A loop control variable that is repeatedly modified. C) A loop body that is never executed. D) A loop condition that is always false.

A) A loop condition that is never false

Why is the input data for the standard_deviation program stored in a list? A) Because the data needs to be processed more than once. B) Because the input is stored in a file. C) Because the formula requires a square root operation. D) Because the input data is formatted into rows and columns.

A) Because the data needs to be processed more than once (First, the mean is calculated, then the mean is subtracted from each value as part of the standard deviation calculation.)

Which of the following would cause a runtime error? A) Dividing by zero. B) Computing the wrong result. C) Misspelling a keyword. D) Leaving a quotation mark off of the end of a character string.

A) Dividing by zero

What is the output of the following statement? print('He said \\Expelliarmus\\'); A) He said \Expelliarmus\ B) He said \\Expelliarmus\\ C) He said 'Expelliarmus' D) He said \'Expelliarmus\' E) No output. This statement contains a syntax error.

A) He said \Expelliarmus\

An entire module can be imported using one import statement. A) True B) False

A) True

An if statement affects a program's flow of control. A) True B) False

A) True

An import statement finds a module and binds it to a name you can use in a program. A) True B) False

A) True

Each Person object has its own last name. A) True B) False

A) True

Finding a minimum value requires that every element in the list be examined. A) True B) False

A) True

If A and B are both false, then the expression A and B is false. A) True B) False

A) True

If A is false, then the B operand in the expression A and B is not evaluated. A) True B) False

A) True

If A is true and B is false, then the expression A or B is true. A) True B) False

A) True

In some cases, a sentinel value can be used to signal the end of input. A) True B) False

A) True

In the honeycomb program, the draw_honeycomb function calls the draw_hexagon function. A) True B) False

A) True

In the palindromes program, a potential palindrome is evaluated by comparing characters at both ends and working inwards. A) True B) False

A) True

The break and continue statements both alter the flow of control in a loop. A) True B) False

A) True

The content of the dictionary used in the Hello World Translator program is read from an input file. A) True B) False

A) True

The set method can be used to set the value of a text field. A) True B) False

A) True

The subsample method is used to scale an image smaller, but not larger. A) True B) False

A) True

The text of a Button can be displayed in various fonts. A) True B) False

A) True

The values stored in a list can be changed. A) True B) False

A) True

When using relational operators to compare character strings, 'Music' comes before 'music'. A) True B) False

A) True

A two-dimensional list is really a one-dimensional list of one-dimensional lists. A) True B) False

A) True (Each dimension is a single-dimensional list.)

Which of the following expressions could be used to determine if a is not less than b? A) a >= b B) a < b C) a > b D) a !< b

A) a >= b

Which of the following ovals is thinner than it is tall? A) canvas.create_oval(140, 100, 160, 150) B) canvas.create_oval(150, 135, 230, 195) C) canvas.create_oval(90, 90, 150, 145) D) canvas.create_oval(270, 300, 450, 400)

A) canvas.create_oval(140, 100, 160, 150)

Which of the following rectangles extends furthest down? A) canvas.create_rectangle(50, 85, 120, 160) B) canvas.create_rectangle(100, 50, 150, 150) C) canvas.create_rectangle(150, 90, 220, 135) D) canvas.create_rectangle(80, 25, 180, 155)

A) canvas.create_rectangle(50, 85, 120, 160)

Which assignment statement is functionally equivalent to the following if statement? if num1 > total: num1 = total else num1 = 0 A) num1 = total if num1 > total else 0 B) num1 = 0 if total > 0 else total C) num1 = 0 if num1 > total else total D) num1 = total if num1 > 0 else 0

A) num1 = total if num1 > total else 0

What output is produced by the following code?print('oak', 'elm', 'pine', end='!', sep='#') A) oak#elm#pine! B) oak#! elm#! pine#! C) oak#!elm#!pine! D) oak!elm!pine#

A) oak#elm#pine! (Each value printed is separated by a # and the output ends with a !)

The Python type conversion functions are actually what kind of functions? A) object constructors B) predicate functions C) iterators D) user-defined types

A) object constructors

Which statement would produce the following output? Eeny Meeny Miny Moe A) print('Eeny\n\tMeeny\nMiny\n\tMoe'); B) print('Eeny\t\tMeeny\tMiny\t\tMoe'); C) print('Eeny\t\nMeeny\tMiny\t\nMoe'); D) print('Eeny\n\tMeeny\n\tMiny\n\tMoe');

A) print('Eeny\n\tMeeny\nMiny\n\tMoe'); (\t is a horizontal tab and \n is a newline charcter (which sends the output to the next line)

EXAMPLE: PLAYING CARDS section

Answers are based on info in this section (go to week of 3/29)

EXAMPLE: COUNTING LETTERS section

Answers are based on the info in this section (go to week of 3/22)

A Canvas text string cannot contain a newline (\n) character. A) True B) False

B) False

Strings containing non-alphabetic characters cannot be compared using the relational operators. A) True B) False

B) False

Text color is determined by the font applied when calling the create_text method. A) True B) False

B) False

The Pillow package is part of the Python Standard Library. A) True B) False

B) False

The askcolor method is defined in the webcolors module. A) True B) False

B) False

The leftmost end point of a line segment must be specified as the start point of the line. A) True B) False

B) False

The loop in the star program controls how long each line in the star is. A) True B) False

B) False

The not operator requires two operands. A) True B) False

B) False

The random values used in the starbursts program were all determined by calls to the randint function from the Python Standard Library. A) True B) False

B) False

The size of a Text widget is specified using a string that indicates the width and height in pixels. A) True B) False

B) False

When a color chooser is first displayed, the initial color selected is black. A) True B) False

B) False

When using relational operators to compare character strings, 'ZEBRA' comes before 'ALLIGATOR'. A) True B) False

B) False

You must use a print statement to display the result of an expression in the Python shell. A) True B) False

B) False

The step value passed as an argument to the range function cannot be negative. A) True B) False

B) False (A negative step value creates a descending range of values)

A Python block comment begins with a double slash (//). A) True B) False

B) False (Each line of a block comment begins with # character (it's really just a series of regular comments)

The smallest index of any dimension of a two-dimensional list is 1. A) True B) False

B) False (The indexes of each dimension begin at 0.)

If a variable called user_id refers to the string 'AEinstein12', what is the result of the expression user_id.isalpha()? A) True B) False

B) False (The isalpha method returns true only if all characters in the string are alphabetic.)

The sample function in the random module takes a sample with replacement. A) True B) False

B) False (The sample function takes a sample without replacement, which means all elements in the sample will be unique.)

A for loop can be used to traverse a dictionary's keys, but not its values. A) True B) False

B) False (The values method returns a list of values you can traverse using a for loop.)

The body of a for loop cannot contain another for loop. A) True B) False

B) False. ( It's called a nested loop. The inner loop executes fully on each iteration of the outer loop)

A binary search only works if the number of elements to search is odd. A) True B) False

B) False. (A binary search can be performed on any number of elements.)

A dictionary key must be a character string. A) True B) False

B) False. (A key can be any immutable type, including, for instance, an integer.)

A binary search works best on an unsorted list of values. A) True B) False

B) False. (For binary search to work at all, the list of values must already be sorted)

The Hello World Translator program will produce an error if the language requested is not in the dictionary. A) True B) False

B) False. (It checks the language and breaks out of the loop if it is not in the dictionary.)

Functions of the math module are used to compute the mean of the data values in the standard_deviation program. A) True B) False

B) False. (No math module functions are needed to compute the mean.)

The standard_deviation program would not work if there were twice as many values in the data file. A) True B) False

B) False. (Since there is generally no limit on the number of elements a list can hold, the input file could potentially be huge)

The maximum number of sides on a Die object is 20. A) True B) False

B) False. (There is no maximum value for the number of sides on a Die.)

A dictionary is bidirectional — values can be used to look up keys and vice versa. A) True B) False

B) False. (There's only one direction: keys are used to look up values.)

Who developed the Python programming language? A) Bjarne Stroustrup B) Guido van Rossum C) Yukihiro Matsumoto D) James Gosling

B) Guido van Rossum

What output is printed by the following code? str = 'Rephactor Python' index = 0 num = 0 while index < len(str): if str[index] == 'o': num += 1 index += 1 print('Num:', num) A) Num: 0 B) Num: 2 C) Num: 10 D) Num: 16 E) No output because the code contains an infinite loop.

B) Num: 2

What is syntax coloring? A) Displaying program output in particular colors B) Showing certain elements of program code in different colors C) Wrapping program output in colored boxes D) Displaying each method of a program in a different color

B) Showing certain elements of program code in different colors

If the value of weight is 7, what does the following statement print? print('The weight is ' + ('even' if weight % 2 == 0 else 'odd')) A) The weight is even B) The weight is odd C) The weight is void D) The weight is NAN

B) The weight is odd. (The condition is false so 'odd' is concatenated to the output.)

Overriding occurs in which of the following situations? A) When a subclass calls a method from a superclass. B) When a subclass redefines a method it inherits from a superclass. C) When a subclass adds a new function that was not inherited from a superclass. D) When a subclass is derived from more than one superclass.

B) When a subclass redefines a method it inherits from a superclass

What output will the following code produce? list1 = [2, 9, 5, 7] list2 = [1, 4, 2, 3] print(list1 + list2) A) [3, 13, 7, 10] B) [2, 9, 5, 7, 1, 4, 2, 3] C) [1, 2, 2, 3, 4, 5, 7, 9] D) [21, 94, 52, 73]

B) [2, 9, 5, 7, 1, 4, 2, 3]

Given the following line of code, which list is produced by the expression values[4:]? values = [79, 40, 18, 32, 95, 66, 58, 81, 20, 62] A) [95, 66] B) [95, 66, 58, 81, 20, 62] C) [32, 95, 66, 58, 81, 20, 62] D) [32, 95, 66]

B) [95, 66, 58, 81, 20, 62]

When performing a binary search, how many comparisons are required to find a value in a list of N values, in the worst case? A) 1 B) log2N + 1 C) N / 2 D) N2

B) log2N + 1

If a variable called business refers to the string 'Time Warner', what is the result of the expression business[6]? A) ' ' B) 'r' C) 'a' D) 'W'

C) 'a' (string indexes start at 0)

Which of the following conclusions is NOT true when using relational operators to compare character strings? A) 'Dracula' comes before 'Frankenstein' B) 'bemuse' comes before 'bewitch' C) 'reset' comes before 'reserve' D) 'desk' comes before 'desktop'

C) 'reset' comes before 'reserve'

If a variable called pioneer refers to the string 'Grace Murray Hopper', what is the result of the expression len(pioneer)? A) 17 B) 18 C) 19 D) 20

C) 19 ( The len built-in function returns the number of characters in the string)

What is the result of the expression 7 // 2? A) 0 B) 1 C) 3 D) 3.5

C) 3

Given the following line of code, what is the value of the expression nums.index(80, 2)? nums = [30, 80, 40, 80, 20, 20, 70, 30, 80] A) 1 B) 2 C) 3 D) 4

C) 3. (That's the index of the first occurrence of 80 when starting the search at index 2.)

Given the following line of code, what is the value of the expression nums.count(80)? nums = [30, 80, 40, 80, 20, 20, 70, 30, 80] A) 1 B) 2 C) 3 D) 4

C) 3. (That's the number of times the value 80 is found in the list.)

If the current value of the variable num is 4, what value will be stored in num after the following line of code is executed? num += 2 A) 2 B) 4 C) 6 D) 8

C) 6

The expression random.randint(6, 12) will produce a value in what range? A) 5 to 11 B) 6 to 11 C) 6 to 12 D) 6 to 13

C) 6 to 12

What is lexicographic ordering? A) Ordering strings based on their length. B) Ordering letters based on their case (lowercase or uppercase). C) Ordering characters based on a character set. D) Ordering words based on their language. E) Ordering sushi at a Japanese restaurant.

C) Ordering characters based on a character set

What output does the following code produce?print('apple', 'banana') A) applebanana B) apple banana C) apple banana D) apple, banana

C) apple banana (The print function separates its output by a space by default)

Which of the following creates the largest circle? A) canvas.create_oval(20, 100, 50, 130) B) canvas.create_oval(150, 175, 195, 220) C) canvas.create_oval(50, 50, 150, 150) D) canvas.create_oval(30, 80, 55, 105)

C) canvas.create_oval(50, 50, 150, 150). (this circle has a radius of 50)

For Python, the term data type can be used interchangeably with what other term? A) object B) index C) class D) sequence

C) class. (class is used to define an object, and all values are objects in Python)

What is text that requests user input called? A) cue B) poll C) prompt D) solicitation

C) prompt

Which of the following is an appropriate analogy? A) Class: score, Object: scoreboard B) Class: house, Object: blueprint C) Class: cookie, Object: cookie cutter D) Class: concept of a dog, Object: my dog Fido

D) Class: concept of a dog, Object: my dog Fido

Which of the following is NOT a reason to use a constant? A) Constants make maintenance tasks easier and safer. B) Constants prevent inadvertent programming errors. C) Constants convey more meaning than literals. D) Constants minimize the need for input validation.

D) Constants minimize the need for input validation

EXAMPLE: CONVERSATION section

This is based off of the flowchart in this section- go to week of 2/1 to see more

If a variable called word refers to the string 'committee', what is the result of the expression word.strip('m')? A) 'committee' B) 'coittee' C) 'comittee' D) 'co'

A) 'committee'

If the variable word refers to the string 'programming', what does the expression word[2:] produce? A) 'ogramming' B) 'rogram' C) 'ogram' D) 'rogramming'

A) 'ogramming'

If the variable blah_blah refers to the string 'gobbledygook', what does the expression blah_blah[-5:] produce? A) 'ygook' B) 'gook' C) 'dygook' D) 'gobbl'

A) 'ygook'

Which range is produced by the function call range(12, 5, -2)? A) 12 10 8 6 B) 11 10 9 8 7 6 5 C) 12 10 8 6 4 D) 10 8 6

A) 12 10 8 6

What value is printed by the following code? my_list = [53, 17, 39, 22, 81, 69] print(my_list[3]) A) 22 B) 39 C) 17 D) 6

A) 22. (indexes begin at 0)

What is the result of the expression 43 % 5? 1) 3 2) 4 3) 8 4) 8.6

A) 3 (remainder of 3)

Which range is produced by the function call range(4, 10)? A) 4 5 6 7 8 9 B) 5 6 7 8 9 C) 5 6 7 8 9 10 D) 4 5 6 7 8 9 10

A) 4 5 6 7 8 9

Which image formats are reliably supported by Tkinter? A) PNG and GIF B) JPG and PNG C) JPG and GIF D) BMP and PNG

A) PNG and GIF

To display an image on a Canvas, it must be represented using which kind of object? A) PhotoImage B) Image C) CanvasImage D) ImageView

A) PhotoImage

If a variable called greeting refers to the string 'hello', what does the expression greeting.upper() accomplish? A) Returns a new string containing the characters 'HELLO' B) Converts the characters in the string object to 'Hello' C) Returns a new string containing the characters 'Hello' D) Converts the characters in the string object to 'HELLO'

A) Returns a new string containing the characters 'HELLO'

Which of the following statements is true? A) The break statement terminates the loop completely. B) The break statement breaks out of the outermost loop. C) The break statement terminates the current iteration of the loop. D) The break statement causes an error to be generated.

A) The break statement terminates the loop completely

A check button does not have to have an event handler. A) True B) False

A) True

A class represents a group of similar objects. A) True B) False

A) True

A color chooser is a specialized dialog box that lets the user select a color. A) True B) False

A) True

A comment in a Python program is ignored by the interpreter. A) True B) False

A) True

A generator expression has the same basic syntax as a list comprehension. A) True B) False

A) True

A pass statement can be used as the body of an if statement, for loop, function definition, or class definition. A) True B) False

A) True

A subclass is a more specific version of its superclass. A) True B) False

A) True

A two-dimensional list is suitable for storing tabular data. A) True B) False

A) True

A while loop affects a program's flow of control. A) True B) False

A) True

An object created from a class is called an instance of that class. A) True B) False

A) True

An object's __str__ method is called automatically when an object is printed. A) True B) False

A) True

Cropping an Image object does not change the original image file. A) True B) False

A) True

Defining a class is an alternative to using a dictionary as a record. A) True B) False

A) True

Each object has its own instance data. A) True B) False

A) True

If a is b is true, then a == b will also be true. A) True B) False

A) True

If an invalid number of sides is provided when a Die object is created, a die with 6 sides is created. A) True B) False

A) True

If either or both operands to the division operator (//) are floating-point values, then the result will be a floating-point value. A) True B) False

A) True

If you use a from clause on an import statement, you don't have to use the module name to refer to a function from that module. A) True B) False

A) True

In a programming language, a syntactically valid statement has only one meaning. A) True B) False

A) True

In the palindromes program, the inner loop evaluates one string to see if it is a palindrome. A) True B) False

A) True

In the palindromes program, the inner loop will not continue comparing characters once the it's determined that the string is not a palindrome. A) True B) False

A) True

Python comments begin with a hash mark (#) and extend to the end of the line. A) True B) False

A) True

Python is a general-purpose programming language, appropriate for solving problems in many areas of computing. A) True B) False

A) True

Python is probably the most popular programming language for data science. A) True B) False

A) True

Python variables are created using an assignment statement. A) True B) False

A) True

Radio buttons work in a group to provide a set of mutually-exclusive options. A) True B) False

A) True

Setting the turtle's speed to 0 turns off the animation of the turtle movement completely. A) True B) False

A) True

The Greek mathematician Eratosthenes came up with the idea of using a sieve algorithm to find prime numbers. A) True B) False

A) True

The Pillow package can be used to perform more sophisticated image manipulation than the Tkinter package. A) True B) False

A) True

The Python for loop is what other languages refer to as a for-each loop. A) True B) False

A) True

The Unicode character set currently represents over 100,000 characters. A) True B) False

A) True

The body of a while loop may never execute. A) True B) False

A) True

The dictionary used in the Hello World Translator program uses the language name as the key. A) True B) False

A) True

The event handler for a Button can be specified using a parameter to the Button constructor. A) True B) False

A) True

The file chooser dialogs may look different on different types of computers. A) True B) False

A) True

The file chooser functions accept optional parameters that let you specify, for instance, the initial directory or file selected. A) True B) False

A) True

The function askopenfiles returns a list of file objects. A) True B) False

A) True

The human eye has three types of color receptors that correspond to wavelengths of red, green, and blue. A) True B) False

A) True

The in and is operators both produce boolean results. A) True B) False

A) True

The in operator can be used to check the contents of a character string or a list. A) True B) False

A) True

The initializer method of the Person class is called __init__. A) True B) False

A) True

The items method returns a list of key/value tuples for all entries in a dictionary. A) True B) False

A) True

The loop in the curved spiral program controls both how many lines are drawn and how long each one is. A) True B) False

A) True

The maximum indexes of a two-dimensional list with 6 rows and 10 columns are 5 and 9, respectively. A) True B) False

A) True

Two functions can have the same name if they are in different modules. A) True B) False

A) True

Using a while loop to check each input value for correctness is a form of input validation. A) True B) False

A) True

Using square brackets to retrieve a value will result in a KeyError if the key is not in the dictionary. A) True B) False

A) True

Variables declared inside a function cannot be accessed from outside that function. A) True B) False

A) True

When using a dictionary as a record, the name of the attribute is used as the key. A) True B) False

A) True

You can use the is operator to check if a variable contains a certain type of data. A) True B) False

A) True

A with statement will automatically close an open file when processing is complete. A) True B) False

A) True (Output files, especially, need to be closed correctly or data may be lost.)

The turtle circle command can be used to draw a regular polygon. A) True B) False

A) True (The optional parameter steps determines how many sides the approximating polygon will have.)

The position of text on a Canvas is specified by the first two arguments to the create_text method. A) True B) False

A) True (They make up an (x, y) coordinate point to position the text.)

Checking to see if an element is in a set is an efficient operation in Python. A) True B) False

A) True. (The operation is performed in constant time, which means the size of the set doesn't matter.)

The stop value passed as an argument to the range function is NOT included in the range produced. A) True B) False

A) True. (the range runs up to but doesn't include the stop value)

What does list contain after the following code is executed? list = [77, 41, 92, 30, 38, 12, 63] list.sort() list.insert(2, 88) list.pop(5) A) [12, 30, 88, 38, 41, 77, 92] B) [12, 30, 88, 38, 63, 77, 92] C) [12, 88, 30, 38, 63, 77, 92] D) [92, 77, 88, 63, 41, 30, 12]

A) [12, 30, 88, 38, 41, 77, 92]

Equal contributions of the three components in an RGB color results in various shades of what? A) gray B) green C) blue D) red

A) gray

Which of the following is NOT a repetition statement in Python? A) if statement B) while statement C) for statement D) They are all repetition statements.

A) if statement

Which statement would produce the following output?"Oom Pah Pah Oom Pah Pah," that's how it goes. A) print("\"Oom Pah Pah Oom Pah Pah,\" that's how it goes."); B) print('\nOom Pah Pah Oom Pah Pah,\n that's how it goes.'); C) print(""Oom Pah Pah Oom Pah Pah," that's how it goes."); D) print('\qOom Pah Pah Oom Pah Pah,\q that's how it goes.');

A) print("\"Oom Pah Pah Oom Pah Pah,\" that's how it goes."); (The \" escape sequences are needed to print the quotation marks.)

Which of the following would be most appropriate to choose with a set of check buttons? A) the languages a person speaks B) the highest educational level a person achieved C) your age range (0-12, 13-18, 19-29, etc.) D) your favorite ice cream flavor

A) the languages a person speaks

Given the following line of code, which expression would produce the substring 'ledge'? words = 'Knowledge is power.' A) words[4:9] B) words[5:10] C) words[5:9] D) words[4:8]

A) words[4:9]

If the variable noise refers to the string 'hullaballoo', what does the expression noise[:8] produce? A) 'loo' B) 'hullabal' C) 'laballoo' D) 'hullaball'

B) 'hullabal'

If a variable called address refers to the string '123 Main Street', what is the result of the expression address.find('3')? A) -1 B) 2 C) 3 D) That expression would cause an error.

B) 2 (Since string indexes start at 0, the character '3' is at index 2.)

What value is printed by the following code? my_list = [53, 17, 39, 22, 81, 69] print(my_list[-3]) A) 39 B) 22 C) 81 D) 69 E) No output. An error will occur.

B) 22

How many comparisons are necessary to find the value 43 in the following list using a binary search? 13 25 28 30 39 43 44 58 66 70 78 81 86 88 95 A) 1 B) 3 C) 4 D) 6

B) 3. (The elements examined, in order: 58, 30, 43)

How many times will the following code print the word 'wow'? for val in range(5, 10): print('wow') A) 4 B) 5 C) 6 D) 9 E) 10

B) 5

What is ASCII? A) A technique for ordering Unicode characters. B) A subset of Unicode containing primarily English characters and basic symbols. C) A technique for representing Unicode characters in memory. D) A set of non-printable Unicode characters. E) None of the above.

B) A subset of Unicode containing primarily English characters and basic symbols

What is the output of the following code? die = Die(6) print('Die value:', die) A) Die value: 0 B) Die value: 1 C) Die value: 6 D) A random number from 1 to 6 will be printed.

B) Die value: 1

A Python comment cannot appear on a line that contains an executable statement. A) True B) False

B) False

A Python function must have at least one parameter. A) True B) False

B) False

A Python list cannot contain a list as an element. A) True B) False

B) False

A Python program must compiled into an executable form before it can be run. A) True B) False

B) False

A character encoding is the list of all characters used by a programming language. A) True B) False

B) False

A comprehension always produces a list. A) True B) False

B) False

A linear search examines every element in the list. A) True B) False

B) False

A nested loop is required to draw a squared-corner spiral. A) True B) False

B) False

A polygon or polyline can have at most 10 vertices. A) True B) False

B) False

A polyline is created using a call to the create_polyline method. A) True B) False

B) False

All Python data types are immutable. A) True B) False

B) False

All elements in a Python list must have the same data type. A) True B) False

B) False

All values stored in a Python dictionary must be unique. A) True B) False

B) False

An assignment statement affects a program's flow of control. A) True B) False

B) False

If left unspecified, the font applied to text displayed on a Canvas is 12-point Lucinda Grande. A) True B) False

B) False

In Python, a class can only be derived from one parent class. A) True B) False

B) False

In the honeycomb program, the draw_hexagon function is called seven times. A) True B) False

B) False

In the starbursts program, the number of starbursts drawn is determined randomly. A) True B) False

B) False

Only one radio button displayed in a window can be selected at any time. A) True B) False

B) False

Python constants cannot be created for floating-point values. A) True B) False

B) False

Python is dynamically typed, meaning each variable can only store one type of value. A) True B) False

B) False

Selecting a check button will automatically unselect any other check buttons in its group. A) True B) False

B) False

The Die class is part of the Python Standard Library. A) True B) False

B) False

The Olympic rings program uses a loop to draw the five rings. A) True B) False

B) False

The break statement is essentially the same as a GOTO statement in older programming languages. A) True B) False

B) False

The prime_sieve program uses a list of integers and sets the value to 0 when a number is determined not to be prime. A) True B) False

B) False

The start value passed as an argument to the range function cannot be negative. A) True B) False

B) False

The value of the expression len(list) is one less than the number of elements in the list. A) True B) False

B) False

The values of an object's instance data represent the object's identity. A) True B) False

B) False

The values passed to the create_polygon method represent the lengths of the edges of the polygon. A) True B) False

B) False

The variable a radio button updates determines its visual layout. A) True B) False

B) False

The webcolors module is part of the Python Standard Library. A) True B) False

B) False

The write method automatically adds line numbers to the output. A) True B) False

B) False

There is no way to stop an infinite loop. A) True B) False

B) False

To be sure it has found all possible prime numbers up to a certain number N, the prime_sieve program repeats the sieve algorithm for all values up to N. A) True B) False

B) False

To change the algorithm for finding a minimum value into one that finds a maximum value, the range used in the for loop would change. A) True B) False

B) False

Python represents a color using the CMYK color model. A) True B) False

B) False (Python uses the RGB color model.)

If A is false, then the B operand in the expression A or B is not evaluated. A) True B) False

B) False (Since A is false, the truth value of an or expression won't be known until B is evaluated.)

The choice function in the random module lets you choose multiple elements from a list. A) True B) False

B) False (The choice function returns only one element from the sequence.)

The maximum number of dimensions a Python list can have is 3. A) True B) False

B) False (The concept of a multidimensional list can be extended to any number of dimensions)

The primary difference between lists and tuples is that lists are immutable and tuples are not. A) True B) False

B) False (You can change the contents of a list but not of a tuple.)

When printed, a set containing strings will list the elements in alphabetical order. A) True B) False

B) False. (The elements of a set are unordered. You should NOT assume the elements can be accessed or printed in any particular order.)

In the random turtle walk program, the loop control variable is used to determine whether the turtle turns right or left. A) True B) False

B) False. (The if statement inside the loop makes that determination with a call to random.choice)

The read method of a file object reads the contents of a file one line at a time. A) True B) False

B) False. (The read method reads the entire contents of a file, or a specific number of characters.)

Which of the following is not a good description of the goal of data science? A) Use data to gain insight, and use insight to take action. B) Protect data against invalid access. C) Turn data into information, and information into knowledge. D) Use data to answer real-world questions.

B) Protect data against invalid access

Which Tkinter text field widget allows for multiple lines of input? A) Entry B) Text C) MLText D) MLEntry

B) Text

What are the names of the two text field widgets in Tkinter? A) EntryField and TextField B) Text and Entry C) Entry and TextField D) Text and TextField

B) Text and Entry

In the flower design program, which diamond is drawn first? A) The one that points northeast. B) The one that points southeast. C) The one that points northwest. D) The one that points southwest.

B) The one that points southeast (The original heading of the turtle to the right (east), and the diamond is created in a clockwise manner.

What does the following statement print? print('Invalid' if count <= 0 else count) A) Zero, or 'Invalid' if count is negative. B) The value of count, or 'Invalid' if count is negative. C) The value of count, or 'Invalid' if count is positive. D) Zero, or 'Invalid' if count is positive.

B) The value of count, or 'Invalid' if count is negative

Which of the following is NOT a constant from the Python Standard Library? A) tkinter.NE B) conversions.KILOMETERS_PER_MILE C) math.e D) math.pi

B) conversions.KILOMETERS_PER_MILE

Which direction would the following arc "point"? That is, where is the center point of the oval relative to the arc?canvas.create_arc(200, 200, 270, 230, start=45, extent=90) A) up B) down C) right D) left

B) down

Given the following line of code, which expression would produce the list ['DE', 'MD', 'VA']? states = ['CA', 'WY', 'DE', 'MD', 'VA', 'FL', 'TX'] A) states[3:5] B) states[2:5] C) states[2:4] D) states[3:6]

B) states[2:5]

If a variable called son refers to the string 'Justin', what is the result of the expression son[-3]? A) 'tin' B) 's' C) 't' D) The expression will generate an interpreter error

C) 't'

Which range is produced by the function call range(5)? A) 1 2 3 4 B) 0 1 2 3 4 5 C) 0 1 2 3 4 D) 1 2 3 4 5

C) 0 1 2 3 4

Given the following line of code, what is the value of the expression nums.index(20)? nums = [30, 80, 40, 80, 20, 20, 70, 30, 80] A) 2 B) 3 C) 4 D) 5

C) 4. (That's the index of the first occurrence of the value 20)

How many comparisons are necessary to find the value 86 in the following list using a binary search? 13 25 28 30 39 43 44 58 66 70 78 81 86 88 95 A) 2 B) 3 C) 4 D) 5

C) 4. (The elements examined, in order: 58, 81, 88, 86)

The expression random.randrange(5, 10) will produce a value in what range? A) 5 to 10 B) 0 to 15 C) 5 to 9 D) 10 to 15

C) 5 to 9

How do you read an integer from a text file? A) By calling the read_int method of the file object. B) By calling the read_num method of the file object. C) By reading it as a string and converting it to an integer. D) By reading it as a floating-point value and truncating it.

C) By reading it as a string and converting it to an interger. (All data read from a text file is initially read as character strings)

What is the role of the seed value of a random number generator? A) It's the maximum value that can be generated. B) It's the minimum value of any range produced by the generator. C) It's a number that is the basis of the calculated pseudorandom numbers. D) It's the maximum number of values that can be produced by the generator.

C) It's a number that is the basis of the calculated pseudorandom numbers

Which of the following would cause a syntax error? A) Dividing by zero. B) Misspelling a word in the output. C) Misspelling a keyword. D) Failing to follow the program specification.

C) Misspelling a keyword

Which of the following contribute to the state of a Car object? A) The variable used to identify the car. B) The ability to turn. C) The car's color. D) The methods of the Car object.

C) The car's color

What is a program's flow of control? A) The order in which interface events are processed. B) The order in which loop bodies are executed. C) The order in which statements are executed. D) The order in which functions are called.

C) The order in which statements are executed

What is the syntax of a language? A) A list of errors that can occur in a program. B) The meaning of a language element. C) The rules that determine how words and symbols can be combined. D) A specification that lists a program's requirements.

C) The rules that determine how words and symbols can be combined

Which of the following is not a good description of the goal of data science? A) Use data to gain insight, and use insight to take action. B) Protect data against invalid access. C) Turn data into information, and information into knowledge. D) Use data to answer real-world questions.

C) Turn data into information, and information into knowledge

Which of the following is a good rule of thumb regarding break and continue statements? A) Avoid using them if at all possible. B) Always use them if the logic of the loop permits it. C) Use them sparingly, and only if they make the logic more readable. D) Use them in for loops but not in while loops.

C) Use them sparingly, and only if they make the logic more readable

What value will the variable my_list hold after the following line of code is executed? my_list = [num for num in range(1, 20) if num % 3 == 0] A) [1, 2, 3] B) [] C) [3, 6, 9, 12, 15, 18] D) [1, 3, 9, 18, 20]

C) [3, 6, 9, 12, 15, 18] (It creates a list containing the multiples of 3 from 1 to 19.)

Which of the following creates a horizontal line? A) canvas.create_line(40, 20, 100, 70) B) canvas.create_line(30, 30, 50, 50) C) canvas.create_line(25, 70, 125, 70) D) canvas.create_line(75, 20, 75, 90)

C) canvas.create_line(25, 70, 125, 70)

What is the default flow of control through a function? A) binary B) repetitious C) linear D) conditional

C) linear

What list of prime values is produced if the prime_sieve program is executed with an input value of 20? A) 1 2 3 5 7 11 13 17 19 B) 2 3 5 7 9 11 13 15 17 19 C) 1 1 2 3 5 8 13 D) 2 3 5 7 11 13 17 19

D) 2 3 5 7 11 13 17 19. (those are all prime numbers less than 20)

What value is stored in num after the following code is executed?list = [2, 4, 6, 8, 10] num = 0 for val in list: if val != 6: num = num + val A) 0 B) 5 C) 10 D) 24 E) 30

D) 24 (The loop computes the sum of all elements in the list except 6.)

What is the result of the expression math.pow(3, 3)? A) 0 B) 6 C) 9 D) 27

D) 27 (3 to the power 3 is 27)

How many elements can be stored in a two-dimensional list with 5 rows and 10 columns? A) 36 B) 40 C) 45 D) 50 E) 66

D) 50. (There are 5 rows and 10 columns, therefore room for 50 elements.)

If the current value of the variable size is 2, what value will be stored in size after the following line of code is executed? size *= 3 A) 2 B) 3 C) 5 D) 6

D) 6

If the current value of the variable count is 2, what value will be stored in count after the following line of code is executed? count += count * 3 A) 2 B) 3 C) 6 D) 8

D) 8

What value is assigned to the variable num by the following statement if the current value of num is 4? num = num * 2 A) 2 B) 4 C) 6 D) 8

D) 8

What is the Python Standard Library? A) A set of officially sanctioned books about Python. B) The set of documents that define the Python language. C) A collection of software tools that support the development of Python programs. D) A collection of programming components that can be used in any Python program.

D) A collection of programming components that can be used in any Python program

What does the Hello World Translator program use to look up the language used given a phrase? A) A while loop B) A dictionary C) A reverse dictionary D) A list comprehension

D) A list comprehension

Python embodies elements of which programming paradigm? A) Procedural programming B) Object-oriented programming C) Functional programming D) All of the above

D) All of the above

Debugging is the process of: A) Demonstrating the a program follows its specification. B) Running a program with all possible inputs. C) Proving that a program produces the correct answers. D) Finding the root cause of an error and fixing it.

D) Finding the root cause of an error and fixing it

Why don't we use natural languages (like English) to program a computer? A) There are too many words and phrases to understand in natural languages. B) It's often hard to understand people when they speak. C) Natural languages don't have syntax rules. D) Natural languages are semantically ambiguous.

D) Natural languages are semantically ambiguous (A statement in a natural language can often have mutliple valid meanings.)

What output does the following code produce?print('Total: ' + 100 + 20) A) Total: 120 B) Total: 10020 C) Total: 1000200 D) No output. This line would produce an error.

D) No output. This line would produce an error (You can't concatenate a string and an integer in Python)

Which of the following is NOT an appropriate use case for a Python dictionary? A) Representing a record of related values. B) Looking up a value. C) Counting the frequency of values. D) Representing an ordered sequence of values.

D) Representing an ordered sequence of values. (Dictionaries are not ordered)

Which of the following statements is true when using a dictionary for counting? A) The key is the item list, the value is the count list. B) The key is the count, the value is the item counted. C) The key is the count list, the value is the item list. D) The key is the item counted, the value is the count.

D) The key is the item counted, the value is the count. (The count is incremented every time the item is found.)

Which of the following is NOT a good reason to use a tuple rather than a list? A) Some tuples can be used as keys in a dictionary. B) It establishes that the data should not be changed. C) Accessing tuple elements is faster than accessing list elements. D) Tuples can hold more elements than lists.

D) Tuples can hold more elements than lists. (There is generally no limit to the number of elements you can put in a tuple or a list.)

Given the following line of code, which list is produced by the expression states[-4:]? states = ['CA', 'WY', 'DE', 'MD', 'VA', 'FL', 'TX'] A) ['VA', 'FL', 'TX'] B) ['CA', 'WY', 'DE', 'MD'] C) ['DE', 'MD', 'VA', 'FL', 'TX'] D) ['MD', 'VA', 'FL', 'TX']

D) ['MD', 'VA', 'FL', 'TX']

What does the list states contain after the following code is executed? states = ['NJ', 'TN', 'WI', 'UT'] states.extend(['PA', 'KY', 'NY']) states.remove('UT') states.sort(reverse=True) A) ['NJ', 'TN', 'WI', 'PA', 'KY', 'NY'] B) ['WI', 'UT', 'TN', 'PA', 'NY', 'NJ', 'KY'] C) ['WI', 'PA', 'TN', 'NJ', 'NY', 'KY'] D) ['WI', 'TN', 'PA', 'NY', 'NJ', 'KY']

D) ['WI', 'TN', 'PA', 'NY', 'NJ', 'KY']

Given the following line of code, which list is produced by the expression values[:8]? values = [79, 40, 18, 32, 95, 66, 58, 81, 20, 62] A) [79, 40, 18, 32, 95, 66, 58] B) [18, 32, 95, 66, 58, 81, 20, 62] C) [32, 95, 66, 58, 81, 20, 62] D) [79, 40, 18, 32, 95, 66, 58, 81]

D) [79, 40, 18, 32, 95, 66, 58, 81]

Which of the following arcs is the same as this one? canvas.create_arc(200, 220, 280, 270, start=40, extent=140) A) canvas.create_arc(200, 220, 270, 280, start=40, extent=140) B) canvas.create_arc(200, 220, 280, 270, start=-40, extent=-140) C) canvas.create_arc(100, 200, 180, 250, start=40, extent=140) D) canvas.create_arc(200, 220, 280, 270, start=-180, extent=-140)

D) canvas.create_arc(200, 220, 280, 270, start=-180, extent=-140)

Which of the following ovals is also a circle? A) canvas.create_oval(95, 120, 190, 240) B) canvas.create_oval(70, 70, 170, 140) C) canvas.create_oval(150, 150, 300, 250) D) canvas.create_oval(100, 200, 155, 255)

D) canvas.create_oval(100, 200, 155, 255)

Which of the following operations cannot be performed on tuples? A) concatenation B) indexing C) slicing D) element removal

D) element removal. (Since tuples are immutable, elements cannot be added or removed.)

Which of the following methods can be called on a tuple? A) append B) reverse C) extend D) index

D) index

Which direction would the following arc "point"? That is, where is the center point of the oval relative to the arc?canvas.create_arc(170, 100, 220, 160, start=-20, extent=40) A) up B) down C) right D) left

D) left

What technique is used to put Unicode characters and strings in order? A) character encoded ordering B) ASCII ordering C) alphabetical ordering D) lexicographic ordering

D) lexicographic ordering

Which of the following is not a primary contributor to data science? A) domain expertise B) statistics C) computer science D) procurement

D) procurement

Which of the following expressions would produce a value in the range 1 to 10? A) random.randint(1, 11) B) random.randint(1, 9) C) random.randrange(1, 10) D) random.randrange(1, 11)

D) random.randrange(1,11)

Which category of data types represents an ordered collection of values? A) dictionary B) boolean C) numeric D) sequence

D) sequence

Which two terms mean the same thing? A) base class and child class B) parent class and subclass C) child class and superclass D) superclass and parent class

D) superclass and parent class

What do the characters in a Unicode escape sequence represent? A) a range of Unicode characters B) the ASCII code for the equivalent Unicode character C) the set of characters terminating in a particular Unicode character D) the hexadecimal code for a particular Unicode character

D) the hexadecimal code for a particular Unicode character

Which of the following identifiers follows the convention for naming Python variables? A) Total_Value B) TOTAL_VALUE C) totalValue D) total_value

D) total_value

What set is stored in set3 by the following code? set1 = {1, 2, 3, 4, 5} set2 = {3, 4, 5, 6, 7, 8, 9} set3 = set1 - set2 A) {6, 7, 8, 9} B) {1, 2, 3, 4, 5} C) {1, 2, 6, 7, 8, 9} D) {1, 2}

D) {1, 2} (This is the set of all elements that are in set1 but not set2.)

Thonny is best described as which of the following? A) Debugger B) Command shell C) Package manager D) Text editor E) Integrated Development Environment (IDE)

E) Integrated Development Environment (IDE)

INTRODUCTION TO TKINTER section

Refer to this section for vocab matching (quick check week of 4/5

Built-in functions of the Python Standard Library can be used without being imported. A) True B) False

A) True

What output is produced by the following code?print('Jan', 'Feb', 'Mar', sep='-') A) Jan-Feb-Mar B) Jan- Feb- Mar- C) Jan - Feb - Mar D) Jan-Feb-Mar-

A) Jan-Feb-Mar (Each value printed is separated by a dash)

Which of the following statements is true? A) The print statement is a call to a function. B) The print statement sends text output to a printer. C) The print statement sends text output to the editor. D) A print statement must be the first statement in a Python program

A) The print statement is a call to a function

Thonny has a package manager that lets you install and update external Python packages. A) True B) False

A) True

You can store a value in a variable in the Python shell. A) True B) False

A) True

You cannot change the contents of Python character string once it has been created. A) True B) False

A) True (python strings are immutable)

If a variable called jedi refers to the string 'Yoda', what is the result of the expression jedi * 3? A) YodaYodaYoda B) YYYooodddaaa C) 12 D) The expression will generate an interpreter error.

A) YodaYodaYoda

Which line of code is equivalent to the following? depth += 50 * offset A) depth = depth + (50 * offset) B) depth = (depth + 50) * offset C) offset = depth + (50 * offset) D) offset = depth + 50 * offset

A) depth = depth + (50 * offset)

What output is printed by the following code if it is executed when appetizer is 3 and entree is 12? if appetizer > 1: if entree < 7: print('ketchup') else: print('mustard') else: if appetizer < 0: print('mayonnaise') else: print('relish') A) ketchup B) mustard C) mayonnaise D) relish E) salsa F) None of the above

B) mustard

Full documentation about the Python Standard Library can be found online. A) True B) False

A) True

If a filled shape drawn by a turtle is not fully enclosed, Python fills the shape as if the starting point is connected to the end point. A) True B) False

A) True

In Python, the relational operators can be used to put character strings in alphabetical order. A) True B) False

A) True

The Python shell is great for exploring Python language features. A) True B) False

A) True

The Python turtle graphics module is based on the programming language Logo developed in the 1960s. A) True B) False

A) True

The input function always returns the read data as a character string. A) True B) False

A) True

The input, int, and float functions are all built-in functions. A) True B) False

A) True

The math module contains a constant that represents the value pi to several digits. A) True B) False

A) True

The math.pi constant represents pi to 15 decimal places. A) True B) False

A) True

The output of a Python program run in Thonny appears in the shell window. A) True B) False

A) True

The pen color and size determines the color and width of the lines drawn. A) True B) False

A) True

The position of a circle depends on the current heading of the turtle. A) True B) False

A) True

The relational operators all return boolean results. A) True B) False

A) True

The value assigned to a variable could be a floating point number. A) True B) False

A) True

The value of a variable can change throughout a program. A) True B) False

A) True

Thonny displays code using syntax highlighting. A) True B) False

A) True

If the current value of the variable num1 is 2 and the current value of the variable num2 is 3, what value will be stored in num2 after the following line of code is executed? num2 /= num1 * num2 A) 0.0 B) 0.5 C) 1.0 D) 1.5

B) 0.5

Which of the following is NOT a valid Python identifier? A) FIRST_PLACE B) 1stPlace C) first_place D) place1

B) 1stPlace (identifiers cannot begin w a digit)

What issue must be addressed when printing a long character string? A) The string must be subdivided into sections of 50 characters or less. B) A regular string literal cannot span across multiple lines. C) The print method has a maximum number of characters it can accept. D) The print method cannot print character strings.

B) A regular string literal cannot span across multiple lines

Which of the following does the input function NOT do when it is called? A) Wait for the user to type information and press Enter. B) Convert the user input to an integer. C) Return the value typed by the user. D) Print a message if provided.

B) Convert the user input to an interger

All mathematical functions in Python are part of the math module. A) True B) False

B) False

An if statement cannot have both an elif and an else clause. A) True B) False

B) False

In Python, the assignment statement is also an expression. A) True B) False

B) False

In dynamically typed languages, variables are declared to store a specific type of data. A) True B) False

B) False

Python 3 is backwards compatible to Python 2. A) True B) False

B) False

Python variables that represent integers are NOT object reference variables. A) True B) False

B) False

Running a program that contains errors will cause the Thonny development environment to terminate. A) True B) False

B) False

The Python programming language was so named after a snake was discovered in the creator's office. A) True B) False

B) False

The arithmetic operators have a lower precedence than the relational operators. A) True B) False

B) False

The assignment operator has higher precedence than the arithmetic operators. A) True B) False

B) False

The stroke color of a filled turtle shape must be the same as the fill color. A) True B) False

B) False

The value assigned to a variable must be numeric. A) True B) False

B) False

The goto command moves the turtle without drawing a line. A) True B) False

B) False (It will draw a line if the turtle's pen is lowered.)

The expression x ^ y raises the value x to the power y. A) True B) False

B) False (The Python exponentiation operator is **)

The less than operator (<) should not be used to compare floating point values. A) True B) False

B) False (There's no problem using < or > to compare floating point values. The danger comes from comparing them for equality)

The effect of the setheading depends on the current heading of the turtle. A) True B) False

B) False (When setting the heading explicitly, the current heading doesn't matter.)

The origin point (0, 0) of the turtle coordinate system is in the upper left corner of the graphic screen. A) True B) False

B) False (origin point is in center of screen)

If both operands to the remainder operator (%) are positive, a divisor of n will produce a result in the range 1 to n. A) True B) False

B) False. (It will produce a result in the range 0 to n-1)

The input function will produce an error if the value read is not numeric. A) True B) False

B) False. (It's type conversion functions such as int and float that produce an error if necessary.)

What output does the following code produce?print('Ready', end=' ') print('Set', end='') print('Go') A) Ready SetGo B) Ready SetGo C) Ready Set Go D) Ready Set Go

B) Ready SetGo (The end argument is a space in the first call and the empty string in the second call)

What does the term case sensitive mean? A) A Python program must be encased in a human-readable comment. B) The difference between uppercase and lowercase letters matters. C) A Python program is enclosed in, and executed relative to, a program case. D) Each case of a Python print statement must be unique.

B) The difference between uppercase and lowercase letters matters

Which value of num will cause the print statement in the following code to be executed? if num < 15: if num + 7 >= 20: print('There you go!') A) 5 B) 10 C) 13 D) 18

C) 13

What is the result of the expression max(6, 17)? A) 0 B) 6 C) 17 D) 23

C) 17

What is the Python shell? A) An integrated development environment for developing Python programs. B) An alternative to IDLE or Thonny. C) A window in which Python statements and expressions are executed immediately. D) A help system for Python programming.

C) A window in which Python statements and expressions are executed immediately

Which of the following statements is true? A) An if statement must contain an else clause. B) An if statement is an example of a repetition statement. C) The statements in the body of an if must be indented. D) The body of an if statement must be enclosed in braces.

C) The statements in the body of an if must be indented

What will happen if the variable total has the value 5 when the following code is executed? if total > 8: print('collywobbles') A) The word collywobbles is not printed and an exception is thrown. B) The word collywobbles is not printed, but an error message is. C) The word collywobbles is not printed and processing continues. D) The word collywobbles is printed and then processing continues.

C) The word collywobbles is not printed and processing continues

Which way would the turtle be facing after executing the following code?turtle.setheading(270) turtle.right(20) turtle.left(65) A) down and left (southwest) B) down (south) C) down and right (southeast) D) up and left (northwest) E) up and right (northeast) F) up (north)

C) down and right (southeast). (after facing down, it turns to the southwest slightly, then back to southeast)

Of the options given, what values of the variables height, size, and width would cause the following code to set the variable weight to 100? if height < size: weight = 50 if width < 20: print('short') else: if width > 100: weight = 100 println('tall') A) height = 12, size = 20, width = 200 B) height = 20, size = 12, width = 90 C) height = 15, size = 10, width = 110 D) height = 15, size = 25, width = 50

C) height = 15, size = 10, width = 110

Suppose the integer variable hours contains a value that represents a number of hours. Which of the following expressions will compute how many 24-hour periods are represented by that value, without worrying about any leftover hours. A) hours / 24 + 1 B) hours / 24 C) hours // 24 D) hours % 24

C) hours // 24

If the variable num contains a positive integer, what are the only two possible results of the expression num % 2? A) 1 and 2 B) 0 and 2 C) -1 and 1 D) 0 and 1

D) 0 and 1. (2 either divides the number evenly or there is 1 left over)

Which of the following is NOT a principle embraced by the Python programming language? A) Complex is better than complicated. B) Explicit is better than implicit. C) Readability counts. D) Simple is better than complex. E) Beautiful is better than ugly. F) Verbose is better than succinct.

F) Verbose is better than succinct

If the turtle is currently facing up (north), which way would it be facing after executing the command turtle.right(45)? A) left (west) B) up and left (northwest) C) down and right (southeast) D) right (east) E) down and left (southwest) F) up and right (northeast)

F) up and right (northeast). (The command turns the turtle 45 degrees to the right)


Set pelajaran terkait

Chapter 3: Stress and Illness/Disease

View Set

PTA 215 subluaxtion, dislocations, and Patellofemoral Dysfunction/Anterior Knee Pain

View Set

Finance 3610 - Darrell Crutchley

View Set

Computer Science 105 Chapter 5 Study Guide

View Set

AP Statistics Chapter 7: Sampling Distributions

View Set

ENGLISH FINAL: julius caesar multiple choice

View Set

Java Quiz 2 - Expressions & Variables

View Set