CIS 2300 Final Prep

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

What will be assigned to the variable s_string after the following code executes? special = '1357 Country Ln.' s_string = special[ :4]

'1357'

What will be assigned to the variable s_string after the following code executes? special = '1357 Country Ln.' s_string = special[-3:]

'Ln.'

What are the valid indexes for the string 'New York'?

0 through 7

What will be displayed after the following code is executed? total = 0 for count_1 in range(10): if count_1 == 1: for count_2 in range(5): value = count_1*10+count_2 print(value, end = '__')

10__11__12__13__14__

What will be displayed after the following code is executed? for num in range(0, 20, 5): num += num print(num)

30

What will be displayed after the following code is executed? total = 0 f or count in range(4,6): total += count print(total)

4 9

What will be displayed after the following code is executed? total = 0 for count in range(1,4): total += count print(total)

6

A function is called from the main function for the first time and then calls itself seven times. What is the depth of recursion?

7

What will be assigned to the string variable pattern after the following code executes? i = 3 pattern = 'z' * (5 * i)

: 'zzzzzzzzzzzzzzz'

What is the second step to take in order to apply a recursive approach?

Determine a way to use recursion to solve the problem in all circumstances which cannot be solved without recursion

What is the number of the first index in a dictionary?

Dictionaries are not indexed by number

True of False: In Python there is no restriction on the name of a module file.

False

True of False: One of the drawbacks of a modularized program is that the only structure you can use in such a program is a sequence structure.

False

True of False: The index of the first element in a list is 1, the index of the second element is 2, and so forth.

False

True of False: The remove method removes all occurrences of an item from a list.

False

True or False: <= is an augmented assignment operator.

False

True or False: A function definition specifies what a function does and causes the function to execute.

False

True or False: A list cannot be passed as an argument to a function.

False

True or False: A local variable can be accessed from anywhere in the program.

False

True or False: A while loop is called a pretest loop because the condition is tested after the loop has had one iteration.

False

True or False: A(n) NumberError exception will occur if you try to use an index that is out of range for a particular string

False

True or False: A(n) control-controlled loop causes a statement or set of statements to repeat as long as the condition is true.

False

True or False: A(n) stratification chart is a visual representation of the relationships between functions

False

True or False: Indexing of a string starts at 1 so the index of the first character is 1, the index of the second character is 2, and so forth.

False

True or False: Lists are immutable, which means their elements can be changed in a program.

False

True or False: Python allows you to compare strings, but it is not case sensitive.

False

True or False: Recursive algorithms are always more concise and efficient than iterative algorithms.

False

True or False: Sets and dictionaries are all immutable.

False

True or False: The backword method reverses the order of the items in a list.

False

True or False: The first line in a while loop is referred to as the condition clause.

False

True or False: The following code will display 'yes + no' mystr = 'yes' yourstr = 'no' mystr += yourstr print(mystr)

False

True or False: The following expression is valid: string[i] = 'i'

False

True or False: The isalpha() method returns False if the string contains only alphabetic characters and is at least one character in length.

False

True or False: The islower() method returns a copy of the string with all the alphabetic letters converted to lower case.

False

True or False: The pass keyword is used to pass arguments to a function.

False

True or False: The strip() method returns a copy of the string with all the leading whitespace characters removed but does not remove trailing whitespace characters.

False

True or False: The union of two sets is a set that contains only the elements that appear in both sets.

False

True or False: There must be only one function involved in any recursive solution.

False

True or False: To get the total number of iterations in a nested loop, add the number of iterations in the inner loop to the number in the outer loop

False

True or False: Unlike other languages, in Python the number of values in a function can return is limited to one

False

True or False: when we define a function, we do not have to add a colon mark (:) at the end of the first line.

False

True or False: you cannot use a for loop to iterate over the characters in a string

False

True or False: The built-in function length returns the length of a sequence.

False. (should be "len", not length)

A _______ variable is accessible to all the functions in a program file.

Global

__________ is the process of inspecting data that has been input into a program in order to ensure that the data is valid before it is used in a computation

Input validation

What will display after the following code is executed? def main(): print("Julian", end = ' ') age = 40 def print_age(): age = 32 print(f"{age}")

Julian 40

What will be the output after the following code is executed? def pass_it(x, y): z = x + ", " + y print(z) name2 = "Julian" name1 = "Smith" pass_it(y = name1, x = name2)

Julian, Smith

A _______ variable is created inside a function.

Local

The Python standard library's __________ module contains numerous functions that can be used in mathematical calculations.

Math

A base case is not necessary for all recursive algorithms.

True

A recursive function must have some way to control the number of times it repeats.

True

True of False: Arguments are passed by position to the corresponding parameter variables in a function.

True

True of False: The top-down design breaks down the overall task of a program into a series of subtasks.

True

True of False: an input validation loop is sometimes called an error trap or an error handler.

True

True or False: A dictionary can include the same value several times but cannot include the same key several times.

True

True or False: A good way to repeatedly perform an operation is to write the statements for the task once and then place the statements in a loop that will repeat as many times as necessary.

True

True or False: A keyword argument refers to an argument that specifies which parameter variable the value should be passed to.

True

True or False: A list comprehension is a concise expression that creates a new list by iterating over the elements of an existing list.

True

True or False: A sentinel is a special value that marks the end of a sequence of items.

True

True or False: A sequence is an object that holds multiple items of data

True

True or False: A value-returning function is like a simple function except that when it finishes it returns a value back to the part of the program that called it.

True

True or False: A(n) if-else statement will execute one block of statements if its condition is true or another block if its condition is false.

True

True or False: A(n) sentinel is a special value that marks the end of a sequence of items.

True

True or False: An action in a single alternative decision structure is performed only when the condition is true.

True

True or False: Both of the following for clauses would generate the same number of loop iterations. for num in range(10): for num in range(1, 11, 1):

True

True or False: Different functions can have local variables with the same names.

True

True or False: Each character in a string has a(n) index which specifies its position in the string

True

True or False: Each element in a tuple has an index that specifies its position in the tuple.

True

True or False: Each time a function is called in a recursive solution, the system incurs overhead that is not incurred with a loop.

True

True or False: Expressions that are tested by the if statement are called Boolean expressions.

True

True or False: If the + operator is used on strings, it produces a string that is a combination of the two strings used as its operands.

True

True or False: If you try to retrieve a value from a dictionary using a nonexistent key, a KeyError exception is raised.

True

True or False: In Python, a module's file name should end in .py.

True

True or False: In Python, you would use the for statement to write a count-controlled loop

True

True or False: In a nested loop, the inner loop goes through all of iterations for each iteration of the outer loop

True

True or False: Lists are dynamic data structures such that items may be added to them or removed from them.

True

True or False: Nested decision statements are one way to test more than one condition.

True

True or False: One reason not to use global variables is that it makes a program hard to debug.

True

True or False: Python allows you to pass multiple arguments to a function.

True

True or False: Python function names follow the same rules as those for naming variables.

True

True or False: The approach known as modularization makes a program easier to understand, test, and maintain.

True

True or False: The in operator can be used to determine whether one string is contained in another string.

True

True or False: The index -1 identifies the last character of a string.

True

True or False: The index -1 identifies the last element in a list.

True

True or False: The isdigit() method returns True if the string contains only numeric digits.

True

True or False: The issubset() method can be used to determine whether set1 is a subset of set2.

True

True or False: The main function contains a program's mainline logic which is the overall logic of the program.

True

True or False: The math function ceil(x) returns the smallest integer that is greater than or equal to x.

True

True or False: The randrange function returns a randomly selected value from a specific sequence of numbers.

True

True or False: The set remove and discard methods behave differently only when a specified item is not found in the set.

True

True or False: The sort method rearranges the elements of a list so they are in ascending or descending order.

True

True or False: The union of two sets is a set that contains all the elements of both sets.

True

True or False: To assign a value to a global variable in a function, the global variable must be first declared in the function.

True

True or False: When the operand on the left side of the * symbol is a string and the operand on the right side is an integer, the * becomes the repetition operator.

True

True or False: When, in a recursive solution, function A calls function B which, in turn, calls function A, this is known as indirect recursion.

True

True or False: You would typically use a for loop to iterate over the elements in a set.

True

True or False: functions that are in the standard library are stored in files that are known as modules

True

True or False: if a whole paragraph is included in a single string, the split() method can be used to obtain a list of the sentences in the paragraph.

True

True or False: in python you can have a list of variables on the left side of the argument operator

True

True or False: in slicing, if the end index specifies a position beyond the end of the string, Python will use the length of the string instead

True

True or False: the acronym GIGO refers to the fact that the computer cannot tell the difference between good data and bad data.

True

True or False: the function header marks the beginning of the function definition

True

A Boolean variable can reference one of two values which are

True or False

The __________ exception is raised when a search item is not in the list being searched.

ValueError

What list will be referenced by the variable list_strip after the following code executes? my_string = "03/07/2018" list_strip = my_string.split('/')

['03', '07', '2018']

What is a group of statements that exists within a program for the purpose of performing a specific task?

a function

A value-returning function is

a function that will return a value back to the part of the program that called it

What is a variable used to keep a running total called?

accumulator

A(n) __________ is any piece of data that is passed into a function when the function is called.

argument

In a recursive solution, if the problem cannot be solved now, then a recursive function reduces it to a smaller but similar problem and

calls itself to solve the smaller problem

The function header begins with the keyword __________ and is followed by the name of the function.

def

To refer to a function in a module, what notation does Python use?

dot (.)

The decision structure that has two possible paths of execution is known as

dual alternative

What are the data items in a list called?

elements

Which method would you use to determine whether a certain substring is the suffix of a string?

endswith(substring)

When a function is called by its name during the execution of a program, then it is ______.

executed

If the start index is __________ the end index, the slicing expression will return an empty string.

greater than

The first line in a function definition is known as the function.

header

A(n) __________ chart is also known as a structured chart.

hierarchy

What causes the interpreter to load the contents of the random module into memory?

import random

In order to avoid KeyError exceptions, you can check whether a key is in the dictionary using the __________ operator.

in

Python comes with __________ functions that have already been prewritten for the programmer.

library

Which would be the base case in a recursive solution to the problem of finding the factorial of a number. Recall that the factorial of a non-negative whole number is defined as n! where:

n = 0

When working with multiple sets of data, one would typically use a(n)

nested list

The primary difference between a tuple and a list is that

once a tuple is created, it cannot be changed

A(n) __________ is a variable that receives an argument that is passed into a function.

parameter

The _____________ keyword is ignored by the Python interpreter and can be used as a placeholder for code that will be written later.

pass

Which method would you use to get the value associated with a specific key and remove that key-value pair from the dictionary?

pop

A(n) __________ structure is a structure that causes a statement or a set of statements to execute repeatedly.

repetition

In a value-returning function, the value of the expression that follows the keyword __________ will be sent back to the part of the program that called the function.

return

The __________ of a local variable is the function in which that variable is created.

scope

The process of calling a function requires

several actions to be performed by the computer

A problem can be solved with recursion if it can be broken down into __________ problems.

smaller

In Python, the variable in the for clause is referred to as the __________ because it is the target of an assignment at the beginning of each loop iteration.

target variable

What is the correct structure to create a dictionary of months where each month will be accessed by its month number (for example, January is month 1, April is month 4)?

{ 1 : 'January', 2 : 'February', ... 12 : 'December' }

What does the 'P' in the acronym IPO refer to?

Processing

What defines the depth of recursion?

the number of times the function calls itself

What is the return value of the string method Istrip()?

the string with all leading whitespaces removed

The __________ design technique can be used to break down an algorithm into functions.

top-down

What represents an example to calculate the sum of numbers (that is, an accumulator), given that the number is stored in the variable number and the total is stored in the variable total?

total += number

Which method can be used to add a group of elements to a set?

update


Set pelajaran terkait

CHPTR 7, part 1, Davis. Adv. Assessments w/ Pre & Post

View Set

physical assessment final exam - ATI questions

View Set

Number Properties, Prime Numbers, Prime Factorization

View Set

Ch 9 AA Partnerships: Formation and Operation: Problems

View Set

5 barriers to consumer satisfaction

View Set