VT Python 1064 Rephactor

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

Which statement would produce the following output? "Oom Pah Pah Oom Pah Pah," that's how it goes.

print("\"Oom Pah Pah Oom Pah Pah,\" that's how it goes.");

Which range is produced by the function call range(5)?

0 1 2 3 4

What value is assigned to the variable num by the following statement if the current value of num is 4? (num = num*2)

8

Which of the following is a relational operator?

<=

The amount deposited into a BankAccount is held as instance data of the BankAccount class.

False

The askcolor method is defined in the webcolors module.

False

The body of a for loop cannot contain another for loop.

False

The open function accepts a string argument representing a path/file name and returns a string containing the file's data.

False

The pass statement is useless.

False

The stroke color of a filled turtle shape must be the same as the fill color.

False

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

False

The goto command moves the turtle without drawing a line.

False

The if statement in the High-Low program had to be written so that it checks for the correct guess last.

False

The input function will produce an error if the value read is not numeric.

False

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

False

Python is probably the most popular programming language for data science.

True

The Python shell has an integrated help system.

True

A character encoding is the list of all characters used by a programming language.

false

The file chooser dialogs may look different on different types of computers.

True

The if clause in a comprehension is optional.

True

The math.pi constant represents pi to 15 decimal places.

True

The write method adds a newline character to the end of the output.

false

Which of the following follows the naming convention of a Python variable?

middle_initial

A function can either print output or return a value, but not both.

False

A polygon or polyline can have at most 10 vertices.

False

A polyline is created using a call to the create_polyline method.

False

A program that runs without generating a runtime error will produce correct results.

False

All mathematical functions in Python are part of the math module.

False

All values stored in a Python dictionary must be unique.

False

In Python, a class can only be derived from one parent class.

False

In the Counting Letters examples, the dictionary used to keep track of letter frequencies uses the count as the key.

False

In the High-Low program, it's impossible for the user to guess the target value in one guess.

False

What is ASCII?

A subset of Unicode containing primarily English characters and basic symbols

What is the result of the expression math.floor(12.843)?

12

What is the result of the expression 43 % 5?

3

str

A character string.

What does the following Turtle Graphics command do? turtle.circle(12, steps=6)

Draws a 6-sided polygon with radius 12.

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)

Num: 2

Which image formats are reliably supported by Tkinter?

PNG and GIF

geometry manager

Specifies how GUI elements are laid out visually in a window

Which Tkinter text field widget allows for multiple lines of input?

Text

What do the characters in a Unicode escape sequence represent?

The hexadecimal code for a particular Unicode character

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

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

What output will the following code produce? list1 = [2, 9, 5, 7] list2 = [1, 4, 2, 3] print(list1 + list2)

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

defines something in terms of itself

a non-recursive part of a recursive definition

Algorithm

a step-by-step procedure for solving a problem

In the conversation program, which input value was converted to another type after being entered by the user?

age

Given the following line of code, which expression would produce the substring 'snapper'? young = 'whippersnapper'

all of the above (2/22 String Slicing)

What output does the following code produce? (print('apple', 'banana'))

apple banana

Which of the following arcs is the same as this one? canvas.create_arc(200, 220, 280, 270, start=40, extent=140)

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

print(my_list)

function call

What does the pass statement do?

nothing

Which of the following expressions would produce a value in the range 1 to 10?

random.randrange(1,11)

What range of values would the following expressions produce?

random.randrange(50) = 0-49 random.randrange(10, 30) = 10-29 random.randrange(-10, 12) = (-10)-11 random.randint(5, 20) = 5-20

Which category of data types represents an ordered collection of values?

sequence

A function can return a boolean result.

true

Which way would the turtle be facing after executing the command turtle.setheading(135)?

up and left (northwest)

If the turtle is currently facing up (north), which way would it be facing after executing the command turtle.right(45)?

up and right (northeast)

What output is produced by the following code? print(15 + 30)

45

How many times will the following code print the word 'wow'? for val in range(5, 10): print('wow')

5

Combo box

A widget that combines a text entry field with a dropdown list of selectable options

What is the Python shell?

A window in which Python statements and expressions are executed immediately

Which of the following string literals is NOT valid?

""\n""

What list of prime values is produced if the prime_sieve program is executed with an input value of 20?

2 3 5 7 11 13 17 19

The pass statement has no effect on the program state.

True

The result of a relational operator can be assigned to a variable.

True

The set method can be used to set the value of a text field.

True

The shuffle method in the DeckOfCards class relies on a method from the Python Standard Library.

True

The value of a variable can change throughout a program.

True

Thonny displays code using syntax highlighting.

True

Thonny has a package manager that lets you install and update external Python packages.

True

Two functions can have the same name if they are in different modules.

True

Using square brackets to retrieve a value will result in a KeyError if the key is not in the dictionary.

True

Values passed to functions when the function is called are called arguments, and the the arguments' values are assigned to parameters to be used in the function.

True

When using a dictionary as a record, the name of the attribute is used as the key.

True

When using relational operators to compare character strings, 'Music' comes before 'music'.

True

You cannot change the contents of Python character string once it has been created.

True

Strings containing non-alphabetic characters cannot be compared using the relational operators.

False

The function askopenfilename returns a file object.

False

A class represents a group of similar objects.

True

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

True

Setting the turtle's speed to 0 turns off the animation of the turtle movement completely.

True

Single-line comments are ignored by the Python interpreter, and so are only for human benefit.

True

The ASCII character set is a subset of the Unicode character set.

True

The High-Low program would still work if the initial value of guess were set to -1 instead of -999.

True

The event handler for a Button can be specified using a parameter to the Button constructor.

True

The initial balance of a BankAccount is $0 unless otherwise specified.

True

The math module contains a constant that represents the value pi to several digits.

True

The Greek mathematician Eratosthenes came up with the idea of using a sieve algorithm to find prime numbers.

true

The open function can be used to open an input file or create an output file.

true

The stop value passed as an argument to the range function is NOT included in the range produced.

true

The valid indexes of a tuple run from 0 to one less than the length of the tuple.

true

The values stored in a list can be changed.

true

Using a while loop to check each input value for correctness is a form of input validation.

true

Variables declared inside a function cannot be accessed from outside that function.

true

You can use the is operator to check if a variable contains a certain type of data.

true

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'}

{'m', 's', 'p'}

abs(num)

function call

Equal contributions of the three components in an RGB color results in various shades of what?

gray

Computing the wrong answer is an example of what kind of error?

logic error

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

oak#elm#pine!

Select each of the following expressions that evaluate to True. Assume that the following code is executed first: title = "Harry Potter"

"Alabama" < "Virginia", "word" in "The last word", "Dog" == "Dog", "Cat" <= "Cat"

Which of the following hex strings represents the color white?

'#FFFFFF'

If the variable str refers to the string 'ABC123XYZ', what does the expression str[3:7] produce?

'123X'

If a variable called business refers to the string 'Time Warner', what is the result of the expression business[6]?

'a'

If the variable machine refers to the string 'computer', what does the expression machine[0:len(machine):2] produce?

'cmue'

If a variable called word refers to the string 'committee', what is the result of the expression word.strip('m')?

'committee'

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!')

13

If a variable called pioneer refers to the string 'Grace Murray Hopper', what is the result of the expression len(pioneer)?

19

Which of the following is NOT a valid Python identifier?

1stPlace

What are the top four cards in the deck right after a DeckOfCards object is created?

2 of Clubs, 3 of Clubs, 4 of Clubs, 5 of Clubs

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

22

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

22

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

24

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]

4

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

4

Which range is produced by the function call range(4, 10)?

4 5 6 7 8 9

What is the value of num after the following code is executed? num = 10 num *= 2 val = num + 3 num = num + val

43

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

8

Pseudocode

A language that is independent of any particular programming language.

What does the Hello World Translator program use to look up the language used given a phrase?

A list comprehension

list

A list of values.

bool

A true or false value.

int

A whole number.

Check Button

A widget that allows the user to turn an option on or off

List box

A widget that displays a list of selectable elements

Option menu

A widget that displays a pop-up list of selectable options

Label

A widget that displays text, an image, or both

Progress bar

A widget that displays the status of long-running operations

Radio button

A widget that, when used in a group, provide a set of mutually-exclusive options

The print function does which of the following?

Accepts arguments, Writes output to the console.

tuple

An immutable list of values.

dict

An unordered collection of key/value pairs

set

An unordered collection of unique values.

How many times does the loop body below execute? command = '' words = [] while command != 'quit': command = input('Enter a word: ') words.append(command) print(words)

At least once

Why is the input data for the standard_deviation program stored in a list?

Because the data needs to be processed more than once

Which of the following is an appropriate analogy?

Class: concept of a dog, Object: my dog fido

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

False

A Python function must have at least one parameter.

False

A Python program must be enclosed in curly braces { } to be executed.

False

A Python program must compiled into an executable form before it can be run.

False

A comprehension always produces a list.

False

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

False

A dictionary key must be a character string.

False

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

False

A linear search examines every element in the list.

False

A nested loop is required to draw a squared-corner spiral.

False

A polyline is a closed shape.

False

A turtle draws a filled circle using the fill_circle command.

False

All Python data types are immutable.

False

An assignment statement affects a program's flow of control.

False

An if statement cannot have both an elif and an else clause.

False

An if statement is used to process the user's thoughts on the meaning of life.

False

By default, rectangles and ovals drawn on a Canvas are filled with black.

False

Constants automatically convert between units of measure.

False

Each check button in a Python program must have its own event handler function.

False

Every if statement must be followed by either an else or an elif.

False

Functions of the math module do not have to be imported.

False

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

False

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

False

If an attempt is made to deal a card from an empty DeckOfCards, an error is generated.

False

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

False

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

False

In Python, the assignment statement is also an expression.

False

In dynamically typed languages, variables are declared to store a specific type of data.

False

In the High-Low program, the number of times the while loop will be executed can be calculated before the loop begins.

False

In the honeycomb program, the draw_hexagon function is called seven times.

False

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

False

In the starbursts program, the number of starbursts drawn is determined randomly.

False

Only one radio button displayed in a window can be selected at any time.

False

Python 3 is backwards compatible to Python 2.

False

Python constants cannot be created for floating-point values.

False

Python is dynamically typed, meaning each variable can only store one type of value.

False

Python represents a color using the CMYK color model.

False

Python variables that represent integers are NOT object reference variables.

False

Running a program that contains errors will cause the Thonny development environment to terminate.

False

Selecting a check button will automatically unselect any other check buttons in its group.

False

Text color is determined by the font applied when calling the create_text method.

False

The Card class represents a complete Python program.

False

The Die class is part of the Python Standard Library.

False

The Hello World Translator program will produce an error if the language requested is not in the dictionary.

False

The Olympic rings program uses a loop to draw the five rings.

False

The Pillow package is part of the Python Standard Library.

False

The Python programming language was so named after a snake was discovered in the creator's office.

False

The __str__ method of the BankAccount class calls the print function to produce the output.

False

The __str__ method of the Card class prints a text representation of the card.

False

The arithmetic operators have a lower precedence than the relational operators.

False

The assignment operator has higher precedence than the arithmetic operators.

False

The body of a for loop will contain one statement for each element of the iteration list.

False

The choice function in the random module lets you choose multiple elements from a list.

False

The data science process is linear.

False

The effect of the setheading depends on the current heading of the turtle.

False

The event handler function for a Button must be called handleButton.

False

The expression x ^ y raises the value x to the power y.

False

The from clause of an import statement lets you define an alias for a module or function.

False

The initial position of a turtle is in the upper left corner of the Turtle Graphics window.

False

The leftmost end point of a line segment must be specified as the start point of the line.

False

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

False

The loop in the star program controls how long each line in the star is.

False

The maximum number of sides on a Die object is 20

False

The not operator requires two operands.

False

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

False

The size of a Text widget is specified using a string that indicates the width and height in pixels.

False

The start value passed as an argument to the range function cannot be negative.

False

The statement count = count + 1 will cause an error because no number can be greater than itself.

False

The step value passed as an argument to the range function cannot be negative.

False

The value assigned to a variable must be numeric.

False

The values of an object's instance data represent the object's identity.

False

The values passed to the create_polygon method represent the lengths of the edges of the polygon.

False

The webcolors module is part of the Python Standard Library.

False

The withdraw method of the BankAccount class ensures that the amount withdrawn is less than the balance.

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.

False

Using components from the Python Standard Library is a rare occurrence.

False

When a color chooser is first displayed, the initial color selected is black.

False

When printed, a set containing strings will list the elements in alphabetical order.

False

When using relational operators to compare character strings, 'ZEBRA' comes before 'ALLIGATOR'.

False

You must use a print statement to display the result of an expression in the Python shell.

False

while loops are more commonly used in Python than for loops because they are safer.

False

What is the output of the following statement? print('He said \\Expelliarmus\\');

He said \Expelliarmus\

Thonny is best described as which of the following?

Integrated Development Environment (IDE)

What age would the user have to enter in order to see the part of the conversation regarding the likelihood of rain?

It doesn't matter

What output does the following code produce? print('Total: ' + 100 + 20)

No output. Would produce an error

What is lexicographic ordering?

Ordering characters based on a character set

Python embodies elements of which programming paradigm?

Procedural programming, Object-orientated programming, Functional programming (all of the above)

Which of the following is not a primary contributor to data science?

Procurement

What is text that requests user input called?

Prompt

Which of the following is not a good description of the goal of data science?

Protect data against invalid access

Graphical User Interface (GUI)

Provides "point and click" interaction with a program

The input function does which of the following? Check all that apply

Retrieves input from the user. Writes a prompt to the console. Returns a string.

If a variable called greeting refers to the string 'hello', what does the expression greeting.upper() accomplish?

Returns a new string containing the characters "HELLO"

Attempting to divide by 0 is an example of which type of error?

Runtime error

Tcl/Tk

Scripting language that supports GUI development

List of most famous sorting algorithms

Selection sort Insertion sort Bubble sort Quick sort Merge sort Heap sort

output

The data produced by an algorithm.

What does the term case sensitive mean?

The difference between uppercase and lowercase matters.

If stuff is a list of integers (with at least one element), what value is in the variable x after the code executes? x = stuff[0] for y in stuff: if x < y: x = y

The largest number in the list.

Which of the following is NOT true regarding the return statement?

The last statement in a function must be a return statement

Granularity

The level at which an instruction is expressed.

In the flower design program, which diamond is drawn first?

The one that pints southeast

What is a program's flow of control?

The order in which the statements are executed

Sorting

The process of putting a list of elements in a particular order

What is the syntax of a language?

The rules that determine how words and symbols can be combined

Which of the following statements is true?

The statement in the body of an 'if; must be indented

What is the result of the following Turtle Graphics command? turtle.left(40)

The turtle turns to the left 40 degrees.

What does the following statement print? print('Invalid' if count <= 0 else count)

The value of count or 'Invalid' if count is negative

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

The weight is odd

Which of the following are true statements about triple-quoted strings (such as '''sample''')? Check all that apply.

They can span multiple lines. They are commonly used for docstring comments.

3 The pen color and size determines the color and width of the lines drawn.

True

A Button can display text and an image at the same time.

True

A character string can be used as the condition of an if statement.

True

A check button does not have to have an event handler.

True

A color chooser is a specialized dialog box that lets the user select a color.

True

A cooperating group of radio buttons is determined by the variable each button updates.

True

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

True

A dictionary is designed for efficient value retrieval.

True

A file chooser is a specialized dialog box for selecting files in a directory structure.

True

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

True

A generator expression has the same basic syntax as a list comprehension.

True

A subclass is a more specific version of its superclass.

True

After a function finishes executing, control returns to the place the function was called.

True

An entire module can be imported using one import statement.

True

An import statement finds a module and binds it to a name you can use in a program.

True

An iterative solution to a problem is one that uses loops instead of recursion. The decision to use iteration or recursion for a given problem is one that a programmer should consider carefully. Computing a factorial, for instance, has a pretty straightforward iterative solution:

True

Built-in functions of the Python Standard Library can be used without being imported.

True

Checking to see if an element is in a set is an efficient operation in Python.

True

Cropping an Image object does not change the original image file.

True

Dealing a card removes the Card object from the DeckOfCards object.

True

Defining a class is an alternative to using a dictionary as a record.

True

Each Person object has its own last name.

True

Each object has its own instance data.

True

Full documentation about the Python Standard Library can be found online.

True

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

True

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

True

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

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.

True

If an invalid number of sides is provided when a Die object is created, a die with 6 sides is created.

True

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

True

If the user input indicates that the likelihood of rain is 'certain', it will be treated as a negative response.

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.

True

In Python, the relational operators can be used to put character strings in alphabetical order.

True

In a programming language, a syntactically valid statement has only one meaning.

True

In programming, recursion is a technique in which a function calls itself in order to solve a problem

True

In the Counting Letters examples, only letters found in the analyzed text have entries in the dictionary.

True

In the palindromes program, the inner loop evaluates one string to see if it is a palindrome.

True

Lists can have lists as elements.

True

Multi-line comments in Python are actually just triple-quoted strings.

True

Python is a general-purpose programming language, appropriate for solving problems in many areas of computing.

True

Python variables are created using an assignment statement

True

Quadratic sorts slower than log sorts

True

Radio buttons work in a group to provide a set of mutually-exclusive options.

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.

True

The Pillow package can be used to perform more sophisticated image manipulation than the Tkinter package.

True

The Python shell is great for exploring Python language features.

True

The Python turtle graphics module is based on the programming language Logo developed in the 1960s.

True

The analysis of the complete I Have a Dream speech shows that four of the top five frequently used letters are vowels.

True

The askcolor method returns a tuple that specifies the color in two ways.

True

The codes used in Morse Code are influenced by the frequency of letter use in English communication.

True

The content of the dictionary used in the Hello World Translator program is read from an input file.

True

The dictionary used in the Hello World Translator program uses the language name as the key.

True

The differences in case are ignored when processing the user's favorite band.

True

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

True

The function askopenfiles returns a list of file objects.

True

The greatest common divisor (GCD) of two positive integers is the largest integer that divides both numbers evenly (without producing a remainder)

True

The human eye has three types of color receptors that correspond to wavelengths of red, green, and blue.

True

The initializer method of the Person class is called __init__.

True

The input function always returns the read data as a character string.

True

The input, int, and float functions are all built-in functions.

True

The items method returns a list of key/value tuples for all entries in a dictionary.

True

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

True

The output of a Python program run in Thonny appears in the shell window.

True

The parameters to the create_rectangle method represent the upper left corner and lower right corner of the rectangle.

True

The position of a circle depends on the current heading of the turtle.

True

The position of text on a Canvas is specified by the first two arguments to the create_text method.

True

The relational operators all return boolean results.

True

The result of a comprehension could always be created using more verbose code.

True

The subsample method is used to scale an image smaller, but not larger.

True

The text of a Button can be displayed in various fonts.

True

The turtle circle command can be used to draw a regular polygon.

True

The value assigned to a variable could be a floating point number.

True

When drawing a polygon, the order in which the vertices are listed may matter.

True

Whether text is displayed in bold or italic type is specified in the font descriptor.

True

You can store a value in a variable in the Python shell.

True

Which of the following is NOT a good reason to use a tuple rather than a list?

Tuples can hold more elements than lists

Which of the following is a good rule of thumb regarding break and continue statements?

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

Overriding occurs in which of the following situations?

When a subclass redefines a method it inherits from a superclass

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)

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

How do you read an integer from a text file?

by reading it as a string and converting it to an integer

Which of the following ovals is also a circle?

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

Which of the following ovals is thinner than it is tall?

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

Which of the following creates the largest circle?

canvas.create_oval(50, 50, 150, 150)

Which of the following rectangles extends furthest down?

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

For Python, the term data type can be used interchangeably with what other term?

class

Which of the following is NOT a constant from the Python Standard Library?

conversions.KILOMETERS_PER_MILE

Which of the following is NOT a way to make a separate copy of a list called nums?

copy_nums = nums

recursive definition

defines something in terms of itself

Which line of code is equivalent to the following? depth += 50 * offset

depth = depth + (50*offset)

Which of the following would cause a runtime error?

divide by 0

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)

down

Which way would the turtle be facing after executing the following code? turtle.setheading(270) turtle.right(20) turtle.left(65)

down and right (southeast)

Which of the following operations cannot be performed on tuples?

element removal

Big O notation

eliminates the irrelevant details of a particular algorithm and focuses on how fast it solves the problem in terms of n

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

false

A Python comment cannot appear on a line that contains an executable statement.

false

A Python list cannot contain a list as an element.

false

A binary search only works if the number of elements to search is odd.

false

A binary search works best on an unsorted list of values.

false

All elements in a Python list must have the same data type.

false

Functions of the math module are used to compute the mean of the data values in the standard_deviation program.

false

If a == b is true, then a is b will also be true.

false

The break statement is essentially the same as a GOTO statement in older programming languages.

false

The continue statement must be executed after a break statement is executed.

false

The maximum number of dimensions a Python list can have is 3.

false

The primary difference between lists and tuples is that lists are immutable and tuples are not.

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.

false

The read method of a file object reads the contents of a file one line at a time.

false

The results computed by the standard_deviation program are written out to text data file.

false

The smallest index of any dimension of a two-dimensional list is 1.

false

The standard_deviation program would not work if there were twice as many values in the data file.

false

The string 'i prefer pi' would be considered a palindrome by the original version of the palindromes program.

false

The write method automatically adds line numbers to the output.

false

There is no way to stop an infinite loop.

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.

false

Which of the following is the best way to print each element of a list?

for element in a_list: print(element)

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')

height = 15, size = 10, width = 110

Which of the following methods can be called on a tuple?

index

Which of the following is NOT something that strings and lists have in common?

insert method

Deriving one class from another establishes what kind of relationship between the two classes?

is-a

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)

left

Which of the following represents the highest valid index of a list named my_list?

len(my_list) - 1

What technique is used to put Unicode characters and strings in order?

lexicographic ordering

What is the default flow of control through a function?

linear

What type of object is used to store the cards in the DeckOfCards class?

list

When performing a binary search, how many comparisons are required to find a value in a list of N values, in the worst case?

log2N + 1

Which of the following would cause a syntax error?

misspelling a keyword

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')

mustard

When the following code is executed, what value will be stored in the variable named greeting? def make_greeting(name): print("Hello", name) greeting = make_greeting("Mr. Anderson")

none

Which assignment statement is functionally equivalent to the following if statement? if num1 > total: num1 = total else num1 = 0

num1 = total if num1 > total else 0

The Python type conversion functions are actually what kind of functions?

object constructors

Which statement would produce the following output? Eeny Meeny Miny Moe

print('Eeny\n\tMeeny\nMiny\n\tMoe')

Which of the statements below will produce the following output? Check all that apply. What do you mean by "pretty" handsome?

print('What do you mean by "pretty" handsome?') print("What do you mean by \"pretty\" handsome?")

Which of the following statements is true?

the break statement terminates the loop completely

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

true

A for loop is a good way to access each character in a string.

true

A function parameter ceases to exist when the function returns to the caller.

true

A two-dimensional list is really a one-dimensional list of one-dimensional lists.

true

A two-dimensional list is suitable for storing tabular data.

true

A with statement will automatically close an open file when processing is complete.

true

An if statement affects a program's flow of control.

true

Finding a minimum value requires that every element in the list be examined.

true

If a is b is true, then a == b will also be true.

true

In some cases, a sentinel value can be used to signal the end of input.

true

In the honeycomb program, the draw_honeycomb function calls the draw_hexagon function.

true

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

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.

true

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

true

Python uses the Unicode character set to represent characters.

true

Swapping two elements in a list requires three assignment statements.

true

The Python for loop is what other languages refer to as a for-each loop.

true

The Unicode character set currently represents over 100,000 characters.

true

The best way to read a file line by line is to use a for loop to iterate over the file object itself.

true

The body of a while loop may never execute.

true

The break and continue statements both alter the flow of control in a loop.

true

The in and is operators both produce boolean results.

true

The in operator can be used to check the contents of a character string or a list.

true

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

true

Given this assignment: word = 'circumlocution' What are the results of the following expressions? Include quote marks in your answers.

word[ 3 ] = 'c' word[ 1:8 ] = 'ircumlo' word[ :3 ] = 'cir' word[ 5: ] = 'mlocution' word[ -4 ] = 't' word[ -4: ] = tion'

Given the following line of code, which expression would produce the substring 'ledge'? words = 'Knowledge is power.'

words[4:9]

Insertion sort

works by repeatedly inserting a new value into a portion of the overall list that is already sorted. One element at a time, the sorted sublist grows until the entire list is sorted.

Selection sort

works by repeatedly selecting an element from the unsorted list and putting it into its final, sorted position. The element selected is typically the smallest (least) element.

What operator is used to perform string concatenation in Python?

+

If a variable called address refers to the string '123 Main Street', what is the result of the expression address.find('3')?

2

Which of the following conclusions is NOT true when using relational operators to compare character strings?

'fantastic' comes before '

If the variable noise refers to the string 'hullaballoo', what does the expression noise[:8] produce?

'hullabal'

If the variable word refers to the string 'programming', what does the expression word[2:] produce?

'ogramming'

Which of the following conclusions is NOT true when using relational operators to compare character strings?

'reset' comes before 'reserve'

If a variable called son refers to the string 'Justin', what is the result of the expression son[-3]?

't'

If the variable blah_blah refers to the string 'gobbledygook', what does the expression blah_blah[-5:] produce?

'ygook'

If the variable num contains a positive integer, what are the only two possible results of the expression num % 2?

0 and 1

The expression random.randrange(30) will produce a value in what range?

0 to 29

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

0.5

After the third iteration of the loop, what value is stored in num? num = 0 values = [2, 4, 6, 8] for value in values: num = num + value

12

Assume the function double returns its argument multiplied by 2. What value will the variable x hold after the following line is executed? x = double(4) + double(2)

12

Which range is produced by the function call range(12, 5, -2)?

12 10 8 6

What is the output of the following code? account = BankAccount(1234) account.withdraw(1.0) print(account)

1234: $-1.00

What is the output of the following code? account1 = BankAccount(1234, 100.0) account2 = BankAccount(5678, 50.0) transfer = 25.00 account1.withdraw(transfer) account2.deposit(transfer) print(account1) print(account2)

1234: $75.00 5678: $75.00

What is the result of the expression max(6, 17)?

17

What is the result of the expression math.pow(3, 3)?

27

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]

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]

3

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

3

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

3

What is the result of the expression 7 // 2?

3

The expression random.randrange(5, 10) will produce a value in what range?

5 to 9

A binary search eliminates approximately ___________% of the viable candidates with each value examined.

50

How many elements can be stored in a two-dimensional list with 5 rows and 10 columns?

50

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

6

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

6

The expression random.randint(6, 12) will produce a value in what range?

6 to 12

What is a docstring?

A character string used as a comment in a program

What is the Python Standard Library?

A collection of programing components that can be used in any python program

Entry

A field in which the user can type text input

Event Handler

A function that performs an action when the user interacts with a widget

What is a predicate function?

A function that returns a boolean result.

Flowchart

A graphical representation of the logic of an algorithm.

Natural Language

A language that humans use to communicate, such as French or English.

What causes an infinite loop?

A loop condition that is never false

What is the output of the following code? die = Die(20) die.roll() die.roll() print(die.value)

A random number btw 1 and 20

What issue must be addressed when printing a long character string?

A regular string literal cannot span across multiple lines

Notebook

A set of tabbed frames with one visible at a time

Scale

A slider used to select a numeric value within a range

Canvas

An area in which graphics are drawn

Which of the following is NOT a reason to use a constant?

Constants minimize the need for input validation

widgets

Controls that let the user interact with a program in various ways

Which of the following does the input function NOT do when it is called?

Convert the user input into the integer

What is the output of the following code? die = Die(6) print('Die value:', die)

Die Value: 1

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

False

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

False

The sample function in the random module takes a sample with replacement.

False

The variable a radio button updates determines its visual layout.

False

Debugging is the process of:

Finding the root cause of an error and fixing it

Who developed the Python programming language?

Guido Van Rossum 1989

Assume the function sayHi returns the string 'Hi'. What value will the variable x hold after the following line is executed? x = sayHi() + sayHi() + sayHi()

HiHiHi

What is the role of the seed value of a random number generator?

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

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

Jan-Feb-Mar

What is the type of the result of the following expression? "1,2,3,4".split(",")

List

What is the range of the valid indexes for a list that holds 50 values?

Lowest index: 0 Highest index: 49

Which of the following identifiers follows the naming convention for a Python constant?

MAX_PENALITIES

What output would be produced when the following code is executed? state = 'Mississippi' print(state.replace('is', 'was'))

Mwasswassippi

Why don't we use natural languages (like English) to program a computer?

Natural languages are semantically ambiguous

Tkinter

Package that supports GUI development in Python

To display an image on a Canvas, it must be represented using which kind of object?

PhotoImage

What does "cleaning" data mean?

Preparing data for analysis by improving its structure and organization

What output does the following code produce? print('Ready', end=' ') print('Set', end='') print('Go')

Ready SetGo

What is syntax coloring?

Showing certain elements of program code in different colors

What is the type of the variable grocery in this code? groceries = ["Apples", "Cookies", "Steaks"] for grocery in groceries: print(grocery)

String

What are the names of the two text field widgets in Tkinter?

Text and Entry

Which of the following contribute to the state of a Car object?

The car's color

Input

The data needed by an algorithm to accomplish its task.

Which of the following statements is true when using a dictionary for counting?

The key is the item counted, the value is the count

Which of the following would be most appropriate to choose with a set of check buttons?

The languages a person speaks

Which of the following statements is true?

The print statement is a call to function

What will happen if the variable total has the value 5 when the following code is executed? if total > 8: print('collywobbles')

The word "collywobbles" is not printed and processing continues

An object created from a class is called an instance of that class.

True

An object's __str__ method is called automatically when an object is printed.

True

Which of the following is NOT a principle embraced by the Python programming language?

Verbose is better than succinct

Which of the following is NOT an arc type for a Tkinter Canvas?

WEDGE

If a variable called jedi refers to the string 'Yoda', what is the result of the expression jedi * 3?

YodaYodaYoda

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)

[12,30,88,41,77,92]

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]

[3, 6, 9, 12, 15, 18]

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]

[32,95,66,58,81]

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]

[79,40,18,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()

[82,27,66,99,18,40,93,85,29]

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]

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

Which of the following expressions could be used to determine if a is not less than b?

a >= b

Which of the following creates a horizontal line?

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

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.

hours//24 (Integer division throws the amount leftover away)

Which of the following is NOT a repetition statement in Python?

if statement

"python".strip()

method call

my_list.append()

method call

name.lower()

method call

Which expression can be used to determine if num holds an odd number?

num % 2 == 1

Which statement would produce the following output? XYZ205

print('XYZ' + str(20) + str(5))

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)

right

Given the following line of code, which expression would produce the list ['DE', 'MD', 'VA']? states = ['CA', 'WY', 'DE', 'MD', 'VA', 'FL', 'TX']

states[2:5]

Which Python function can be used to call a method of a superclass?

super

Which two terms mean the same thing?

superclass and parent class

Which of the following identifiers follows the convention for naming Python variables?

total_value

A comment in a Python program is ignored by the interpreter.

true

A while loop affects a program's flow of control.

true

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

{1, 2, 3, 4, 5, 6, 7, 8, 9}

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

{1, 2}

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

{3, 4, 5,}


Kaugnay na mga set ng pag-aaral

Section 4.3: Conditional Probability Multiplication Rule

View Set

Metabolic Functions of the Liver

View Set

Vocabulary Workshop Lessons 3 and 4

View Set