Python Final Exam

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

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

True (Any value less than 2 is considered invalid.)

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

True (Each line in the file contains a language name and the phrase in that language.)

T/F: Dealing a card removes the Card object from the DeckOfCards object.

True (It removes the card from the list and returns it. In that sense, it mimics a real deck of cards.)

T/F: The Thonny debugger lets you trace the value of variables while your program is executing.

True

T/F: The Unicode character set currently represents over 100,000 characters.

True

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

True

T/F: The file chooser dialogs may look different on different types of computers.

True

T/F: The file chooser functions accept optional parameters that let you specify, for instance, the initial directory or file selected

True

T/F: The input, int, and float functions are all built-in functions.

True

T/F: The math module contains a constant that represents the value pi to several digits.

True

T/F: The math.pi constant represents pi to 15 decimal places.

True

T/F: The open function can be used to open an input file or create an output file.

True

T/F: The position of a circle depends on the current heading of the turtle.

True

T/F: The valid indexes of a tuple run from 0 through one less than the length of the tuple

True

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

Verbose is better than succinct

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]

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

a >= b

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

'reset' comes before 'reserve'

Notebook

A set of tabbed frames with one visible at a time

How do you read an integer from a text file?

By reading it as a string and converting it to an integer.

T/F: A dictionary key must be a character string.

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

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

False (That expression returns the length of the list (the number of elements))

T/F: The not operator requires two operands.

False (only had one opperand)

T/F: All mathematical functions in Python are part of the math module.

False (several built-in functions)

T/F: In the palindromes program, the inner loop will stop immediately if the string is determined not to be a palindrome.

True (The variable palindrome keeps track of that.)

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

Tuples can hold more elements than lists. (this is not true! generally no limit)

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 (The super function gives access to the parent class.)

Which of the following adheres to the naming convention for a Python variable?

total_value

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

total_value

T/F: A two-dimensional list is really a one-dimensional list of one-dimensional lists.

True

T/F: After a function finishes executing, control returns to the place the function was called.

True

T/F: An argument can be assigned to a particular parameter when a function is called.

True

T/F: An entire module can be imported using one import statement.

True

Which of the following is the preferred way to embed a quotation mark into a Python string?

'Alice said "Hi" to Bob.'

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

'a'

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

T/F: A nested loop is required to draw a squared-corner spiral.

False

T/F: A program that runs without generating a runtime error will produce correct results.

False

T/F: An if statement cannot have both an elif and an else clause.

False

T/F: If A is false, then the B operand in the expression A or B is not evaluated.

False

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

False

T/F: Python 3 is backwards compatible to Python 2.

False

T/F: Python variables that represent integers are NOT object reference variables.

False

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

False

T/F: The value assigned to a variable must be numeric.

False

T/F: When using relational operators to compare character strings, 'ZEBRA' comes before 'ALLIGATOR'.

False

T/F: In a programming language, a syntactically valid statement has only one meaning.

True

T/F: The function askopenfiles returns a list of file objects.

True

T/F: The set method can be used to set the value of a text field.

True

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

True

T/F: A for loop is a good way to access each character in a string.

True (A string is a sequence of characters that the for loop processes one at a time.)

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

True (Each dimension is indexed from 0 to N-1, where N represents the number of elements in that dimension.)

T/F: Each Person object has its own last name.

True (Each has its own instance variable)

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

True (It can be used for efficient traversal of the entire dictionary.)

T/F: The askcolor method returns a tuple that specifies the color in two ways.

True (It returns the color as an RGB value and as a hex value.)

T/F: An object's __str__ method is called automatically when an object is printed.

True (It's also called when an object is concatenated with a string.)

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

True (Ragged lists have at least one dimension of non-uniform length.)

T/F: The text of a Button can be displayed in various fonts.

True (The font can be specified when the button is created or using the configure method.)

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

True (The loop won't allow processing to proceed until a valid value is entered.)

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

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

T/F: A two-dimensional list is suitable for storing tabular data.

True (The two dimensions of the list correspond to the row and column layout of the table.)

What is text that requests user input called?

prompt

T/F: A Python program must compiled into an executable form before it can be run.

False

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

True

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

True

T/F: The value of a variable can change throughout a program.

True

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

words[4:9]

T/F: Functions of the math module do not have to be imported.

False (not a built in function)

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

False (random.choice)

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

oak#elm#pine!

Debugging is the process of:

Finding the root cause of an error and fixing it.

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

Natural languages are semantically ambiguous (have more than one meaning)

What is the default flow of control through a function?

Linear

Which of the following string literals is NOT valid?

""\n""

Who developed the Python programming language?

Guido van Rossum

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}

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

2 (string index)

Tcl/Tk

Scripting language that supports GUI development

What is the result of the expression 43 % 5

3

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 programming convention?

A guideline about program style that makes code easier to read.

Scale

A slider used to select a numeric value within a range

Which of the following is a relational operator?

<=

Widgets

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

T/F: A character encoding is the list of all characters used by a programming language.

False

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

True

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

'123X'

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

45

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

Because the data needs to be processed more than once.

T/F: The values of an object's instance data represent the object's identity.

False (could be the same)

Which of the following is an appropriate analogy?

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

Which of the following would cause a runtime error?

Diving by 0

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

He said \Expelliarmus\

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

Index

What is lexicographic ordering?

Ordering characters based on a chracter set

Tkinter

Package that supports GUI development in Python

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

True

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

Ready SetGo

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

True

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

Text

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

Which of the following statements is true?

The print statement is a call to a function

Which of the following statements is true?

The statements in the body of an if must be indented.

T/F: Each object has its own instance data.

True

Overriding occurs in which of the following situations?

When a subclass redefines a method it inherits from a superclass.

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

12

What is ASCII?

A subset of Unicode containing primarily English characters and basic symbols.

Canvas

An area in which graphics are drawn

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

Die value: 1

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

True

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

if statement (conditional statement)

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

is-a

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} (intersection)

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'

'committee' (only strips leading or trialing characters)

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

'fantastic' comes before 'Great'

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'

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

'ygook'

One solution is to use an escape sequence, which is a technique for representing a character in situations where the traditional manner would cause problems or simply be less convenient.

-

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

0 1 2 3 4

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

0-29

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

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

2 of Clubs, 2 of Diamonds, 2 of Hearts, 2 of Spades

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

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

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

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 (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.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

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

5 (range contains 5 values 5-9)

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

5 to 9

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

50

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

6 to 12

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

A list comprehension

What is an argument?

A list of all values passed into a function.

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 between 1 and 20

Check Button

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

Combo Box

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

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

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

Convert the user input to an integer.

Which of the following operations cannot be performed on tuples?

Element removal (immutable)

T/F: An assignment statement affects a program's flow of control.

False

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

False

T/F: Strings containing non-alphabetic characters cannot be compared using the relational operators.

False

T/F: The Card class represents a complete Python program.

False

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

False

T/F: The Python interpreter requires all indentation levels to be four spaces.

False

T/F: The __str__ method of the Card class prints a text representation of the card.

False

T/F: The arithmetic operators have a lower precedence than the relational operators.

False

T/F: The event handler function for a Button must be called handleButton.

False

T/F: The results computed by the standard_deviation program are written out to text data file.

False

T/F: The stroke color of a filled turtle shape must be the same as the fill color.

False

T/F: The write method automatically adds line numbers to the output.

False

T/F: Using components from the Python Standard Library is a rare occurrence.

False

T/F: A binary search only works if the number of elements to search is odd.

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

T/F: All elements in a Python list must have the same data type.

False (A list can contain elements with differing types)

T/F: The step value passed as an argument to the range function cannot be negative.

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

T/F: Only one radio button displayed in a window can be selected at any time.

False (A window can display multiple sets of radio buttons that are mutually-exclusive within each group.)

T/F: Selecting a check button will automatically unselect any other check buttons in its group

False (Check buttons don't work in formalized groups. They represent individual boolean situations.)

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

False (Even though it's in all lower case letters, the spaces would throw it off.)

T/F: A binary search works best on an unsorted list of values.

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

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

False (It could be written that way, but in this example no validation of the arguments is performed.)

T/F: The function askopenfilename returns a file object.

False (It returns a string that represents the file name.)

T/F: The askcolor method is defined in the webcolors module.

False (It's defined in the colorchooser module.)

T/F: The amount deposited into a BankAccount is held as instance data of the BankAccount class.

False (It's just passed in as a parameter to the deposit method. Only the account number and balance are instance data.)

T/F: The primary difference between lists and tuples is that lists are immutable and tuples are not.

False (It's the other way around. You can change the contents of a list but not of a tuple)

T/F: Each check button in a Python program must have its own event handler function.

False (Multiple check buttons could use the same event handler, or none at all.)

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

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

T/F: A linear search examines every element in the list.

False (Once the target element is found, there is no need to keep searching the list.)

T/F: In Python, a class can only be derived from one parent class.

False (Python supports multiple inheritance.)

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

False (That's how the window size is specified. The size of a Text widget is specified using optional parameters.)

T/F: The Die class is part of the Python Standard Library.

False (The Die class was written specifically for this example.)

T/F: The __str__ method of the BankAccount class calls the print function to produce the output.

False (The __str__ method doesn't print anything. It formats and returns a string summary of the bank account.)

T/F: The variable a radio button updates determines its visual layout.

False (The associated variable has nothing to do with the visual presentation of the button.)

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

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

T/F: The maximum number of dimensions a Python list can have is 3.

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

T/F: When a color chooser is first displayed, the initial color selected is black.

False (The default color is white, but you can specify the initial color to be any color you'd like.)

T/F: All values stored in a Python dictionary must be unique.

False (The dictionary keys must be unique, but the values could be duplicated.)

T/F: When printed, a set containing strings will list the elements in alphabetical order.

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

T/F: 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 (The for loop could stay the same — the condition of the if statement would change to find the biggest element.)

T/F: The smallest index of any dimension of a two-dimensional list is 1.

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

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

False (The logic of the if statement could be written to check any of the possibilities in any order.)

A Python list cannot contain a list as an element.

False (The nested list is sometimes called a sublist)

T/F: 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 parameter name is called show and it is used in the Entry widget.)

T/F: There is no way to stop an infinite loop.

False (The program must be interrupted by pressing Ctrl-C or Ctrl-Break or by closing the run window.)

T/F: 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 (The program only uses the sieve algorithm up to the square root of N, which is sufficient.)

T/F: 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 program uses a list of boolean values, whose index values are determined to be prime or not.)

T/F: The read method of a file object reads the contents of a file one line at a time.

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

T/F: The sample function in the random module takes a sample with replacement.

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

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

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

T/F: The maximum number of sides on a Die object is 20.

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

T/F: The write method adds a newline character to the end of the output.

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

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

False (a value of none is returned)

T/F: The loop in the star program controls how long each line in the star is.

False (controls how many lines is drawn)

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

False (depends how long it takes the user to guess_

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

False (file could potentially be huge since no limit)

T/F: A turtle draws a filled circle using the fill_circle command.

False (no such command)

T/F: A Python function must have at least one parameter.

False (some have no parameters)

T/F: The body of a for loop cannot contain another for loop.

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

T/F: The start value passed as an argument to the range function cannot be negative.

False(Sure it can. A range can include negative values.)

Thonny is best described as which of the following?

Integrated Development Environment (IDE)

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 type of object is used to store the cards in the DeckOfCards class?

List

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

Mwasswassippi

Graphical User Interface (GUI)

Provides "point and click" interaction with a program

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'

Geometry Manager

Specifies how GUI elements are laid out visually in a window

What does the term case sensitive mean?

The difference between uppercase and lowercase letters matters

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

The language a person speaks

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

The last statement in a function must be a return statement.

What is a program's flow of control?

The order in which statements are executed.

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

True

T/F: A Button can display text and an image at the same time.

True

T/F: A check button does not have to have an event handler.

True

T/F: A class represents a group of similar objects.

True

T/F: A color chooser is a specialized dialog box that lets the user select a color.

True

T/F: A cooperating group of radio buttons is determined by the variable each button updates.

True

T/F: A file chooser is a specialized dialog box for selecting files in a directory structure.

True

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

True

T/F: A function can be called multiple times with different arguments.

True

T/F: A function can return a boolean result.

True

T/F: A function parameter ceases to exist when the function returns to the caller.

True

T/F: A syntactically valid program is not necessarily a good program.

True

T/F: An if statement affects a program's flow of control.

True

T/F: An object created from a class is called an instance of that class.

True

T/F: An output file should be closed explicitly when you're done writing to it.

True

T/F: By default, the first argument passed to a function is assigned to the first parameter.

True

T/F: Full documentation about the Python Standard Library can be found online.

True

T/F: If A and B are both false, then the expression A and B is false.

True

T/F: If A is false, then the B operand in the expression A and B is not evaluated.

True

T/F: If A is true and B is false, then the expression A or B is true.

True

T/F: If an argument has a default value, it is optional in the function call.

True

T/F: Python uses the Unicode character set to represent characters.

True

T/F: Radio buttons work in a group to provide a set of mutually-exclusive options

True

T/F: Swapping two elements in a list requires three assignment statements.

True

T/F: The shuffle method in the DeckOfCards class relies on a method from the Python Standard Library.

True

T/F: Two functions can have the same name if they are in different modules.

True

T/F: When using relational operators to compare character strings, 'Music' comes before 'music'.

True

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

True (Each input value is compared to the sentinel value to know when the loop should terminate.)

T/F: The initializer method of the Person class is called __init__.

True (For any class, the name of the special method that initializes instance data is called __init__.)

A subclass is a more specific version of its superclass.

True (Inheritance should create an is-a relationship.)

T/F: Variables declared inside a function cannot be accessed from outside that function.

True (That's called a local variable, and its scope is limited to the function.)

T/F: The Python for loop is what other languages refer to as a for-each loop.

True (The "regular" for loop in other languages behaves differently.)

T/F: The initial balance of a BankAccount is $0 unless otherwise specified.

True (The balance parameter of the __init__ method defaults to 0 if not provided.)

T/F: The body of a while loop may never execute.

True (The condition is checked first, and if it's false right away, the body of the loop is never executed.)

T/F: The event handler for a Button can be specified using a parameter to the Button constructor.

True (The event handler is set using the command keyword parameter.)

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

True (The indexes in the variables left and right determine which characters are compared.)

T/F: A dictionary is designed for efficient value retrieval.

True (The internal representation of a dictionary is designed to find a value quickly given its key.)

T/F: The dictionary used in the Hello World Translator program uses the language name as the key.

True (The phrase "Hello World!" in the appropriate language is the value for each key.)

T/F: Using the index operator to retrieve a value will result in a KeyError if the key is not in the dictionary.

True (You can use the in operator to check for a key's existence if you're not sure.)

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

True (You might use Python for web development, business applications, and artificial intelligence, among many others.)

T/F: A while loop affects a program's flow of control.

True (loop determines which statement is executed next)

T/F: The values stored in a list can be changed.

True (mutable)

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

True (the outer loop allows multiple strings to be evaluated)

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

YodaYodaYoda

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

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, 38, 41, 77, 92]

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]

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 line of code is equivalent to the following? depth += 50 * offset

depth = depth + (50 * offset)

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)

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

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

lexicographic ordering

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

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

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 statement would produce the following output? Eeny Meeny Miny Moe

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

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

random.randrange(1,11)

Which two terms mean the same thing?

superclass and parent class (This is the class from which a subclass (or child class) is derived.)

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 expression would produce the substring 'snapper'? young = 'whippersnapper'

young[7:14] young[7:] young[-7:] young[7:len(young)]

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

't'

What operator is used to perform string concatenation in Python?

+

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

0 and 1

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

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

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

17

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 is the result of the expression math.pow(3, 3)

27

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

3

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

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

8

What is a docstring?

A character string used as a comment in a program

What is the Python Standard Library?

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

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

A regular string literal cannot span across multiple lines.

In Python, the assignment statement is also an expression.

False

T/F: A Python program must be enclosed in curly braces { } to be executed.

False

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

False

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

False

T/F: The assignment operator has higher precedence than the arithmetic operators.

False

T/F: The effect of the setheading depends on the current heading of the turtle.

False

T/F: The goto command moves the turtle without drawing a line.

False

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

False

T/F: A Python comment cannot appear on a line that contains an executable statement.

False (helps explain it)

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

False (produce a range 0 to n-1)

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

False (starts with #)

T/F: The input function will produce an error if the value read is not numeric.

False (wil produce error if int or float used)

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

Jan-Feb-Mar

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

Logic error

Which of the following would cause a syntax error?

Mispelling a word

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

No output, would produce error because you cannot concatenate a string and an integer

Python embodies elements of which programming paradigm?

Procedural programming Object-oriented programming Functional programming

What is syntax coloring?

Showing certain elements of a program code in different colors

What is the syntax of a language?

The rules that determine how words and symbols can be combined.

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.

T/F: A comment in a Python program is ignored by the interpreter.

True

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

True

T/F: 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

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

True

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

True

T/F: Python variables are created using an assignment statement.

True

T/F: Running a program that contains errors will cause the Thonny development environment to terminate.

True

T/F: Setting the turtle's speed to 0 turns off the animation of the turtle movement completely.

True

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

True

T/F: The input function always returns the read data as a character string.

True

T/F: The output of a Python program run in Thonny appears in the shell window.

True

T/F: The pen color and size determines the color and width of the lines drawn.

True

T/F: The relational operators all return boolean results

True

T/F: The result of a relational operator can be assigned to a variable.

True

T/F: The turtle circle command can be used to draw a regular polygon.

True

T/F: Thonny displays code using syntax highlighting.

True

T/F: You cannot change the contents of Python character string once it has been created.

True

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

apple banana

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)


Set pelajaran terkait

Biology Lecture Quiz 3: Chapter 2 and 3

View Set

Chapter 21 Quiz: Tax COnsiderations

View Set

chapter 9, 10, 11, 12 bio 163 exam

View Set

Social Studies Quiz: Topic 5, Lessons 1-3

View Set