1/99
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
|---|
No study sessions yet.
Which of the following is NOT a reserved keyword in Python?
A. return
B. finally
C. start
D. class
C. start
What is true of arithmetic statements in Python?
A. The Python interpreter always works from left to right with no regard for order of operations.
B. Order of operations, including parentheses, is respected
C. Parentheses cannot be used to enforce operational order
D. Exponentiation is not guaranteed to occur before multiplication because they rely on similar characters.
B. Order of operations, including parentheses, is respected
What is different about running a program as a script by sending a Python file to the Python interpreter versus running commands directly in the Python shell?
A. In script mode, the output of each command will not be output to the screen.
B. When running in the Python shell numbers do not need to be converted to strings contextually.
C. Print statements are ignored when running in the Python shell.
D. You cannot debug a program in script mode.
A. In script mode, the output of each command will not be output to the screen.
Which of the following is true of strings in Python?
A. They do not require quotes.
B. All normal arithmetic operators work on strings.
C. They can be combined with numeric data without conversion.
D. They can be surrounded by single or double quotes.
D. They can be surrounded by single or double quotes.
The process of combining two strings is called...
A. string addition
B. concatenation
C. joining
D. assignment
B. concatenation
Python is an example of what kind of programming language?
A. Compiled
B. Interpreted
C. Natural
D. Binary
B. Interpreted
An expression is different from a statement because...
A. an expression cannot be used in script mode but a statement can be.
B. a statement cannot be used in script mode but an expression can be.
C. an expression produces an effect on the program and a statement does not.
D. a statement produces an effect on the program and an expression does not.
D. a statement produces an effect on the program and an expression does not.
In the following expression, what best describes the relationship between number_of_students and the value 29:
number_of_students = 29
A. number_of_students is a constant identified by 29
B. 29 is assigned to number_of_students
C. 29 is a constant identified by number_of_students
D. 29 is equivalent to number of students
B. 29 is assigned to number_of_students
What is true of variable names in Python?
A. They cannot begin with an uppercase letter.
B. They can include spaces
C. Numbers can be used anywhere in the variable name.
D. They are case sensitive.
D. They are case sensitive.
In a Python program the type of which of the following values are the same?
10
10.0
'10'
A. None are the same.
B. The first two are the same.
C. All are the same.
D. The second two are the same
A. None are the same.
When a piece of data is converted from one type to another type it is called...
A. conversion
B. concatenation
C. polymorphism
D. type casting
D. type casting
Why is it a bad idea to use words such as print and other Python built in functions as variable names?
A. Python will reset your variables while the program is running.
B. It makes the meaning of the code ambiguous.
C. Python will fail with an error if you try to do this.
D. It will overwrite the original value of the function and make it impossible to use that function again.
D. It will overwrite the original value of the function and make it impossible to use that function again.
Which of the following operations is allowed to be used with string data?
A. -
B. *
C. **
D. /
B. *
When is It possible to perform addition on two different types of data using the "+" sign operator in Python?
A. When one value is a number and one is a string representation of a number.
B. When both are numeric types.
C. This is never allowed without an explicit conversion of both values.
D. Python always allows this because it is loosely typed.
B. When both are numeric types.
When capturing user input in Python which of the following is true?
A. Numeric input cannot be captured.
B. Python will always always attempt to convert the data into a number first and will capture it as a string if that fails.
C. The type of data captured from the user's input will be inferred based on the context.
D. All user input will be captured as a string.
D. All user input will be captured as a string.
When a floating point number is converted to an integer how is the original value changed?
A. It is rounded up or down depending on the current value.
B. It is truncated leaving just the whole number portion.
C. The conversion will fail unless the decimal value is zero.
D. It is rounded up to the nearest whole number.
B. It is truncated leaving just the whole number portion.
Which of the following is NOT true of a statement in Python?
A. A statement can be used to change the value stored in a variable.
B. A simple line to print data is a statement.
C. Statements produce an effect on the program.
D. Statements only work with numeric data.
D. Statements only work with numeric data.
When attempting to convert a string value to an integer what will happen if a non-numeric string is used?
A. A false value will be returned.
B. The number will be returned as zero.
C. The program will convert the ascii characters to numbers and return those.
D. The program will crash with an error.
D. The program will crash with an error.
In Python once a variable is set to a specific value...
A. it is set and cannot be reassigned.
B. you must explicitly release the variable from memory in order to reset it.
C. it can be set to any other data of any type.
D. it cannot be set to a value of a different type.
C. it can be set to any other data of any type.
Which of the following is true of variables in Python?
A. Once a variable is set with a value it cannot be changed.
B. The type of value stored in a variable does not need to be defined or declared.
C. Variables are not available in script mode.
D. The type of value stored in a variable must always be declared.
B. The type of value stored in a variable does not need to be defined or declared.
When reading a traceback, which piece of data is NOT available?
A. the data currently stored in the variables.
B. the list of function names that were called.
C. the function name in which the error occurred.
D. the line number on which the error occurred.
A. the data currently stored in the variables.
During the execution of a program, a function that is encountered...
A. must have parameters defined.
B. will not be run until it is called elsewhere in the program.
C. is run immediately.
D. must not contain more lines of code than the non-function code in the program.
B. will not be run until it is called elsewhere in the program.
Which of the following is a valid function header?
A. def hello_world(hello):
B. def print_data:
C. def print data():
D. def print_data(first second):
A. def hello_world(hello):
Which is NOT true of variables created within functions?
A. They can be accessed from outside the function as well as inside the function.
B. They can be passed into the function as parameters.
C. They can have the same name as a variable outside the function.
D. They can store any type of information or data.
A. They can be accessed from outside the function as well as inside the function.
In a Python program, to use a function...
A. the function must return data.
B. it must be defined above the calling code.
C. it must not be a void function.
D. the function can be declared anywhere in the program.
B. it must be defined above the calling code.
Empty parentheses in a function header indicate...
A. that the function is a void function.
B. that the function doesn't take any arguments.
C. that the function can take any number of arguments.
D. that the function does not process data.
B. that the function doesn't take any arguments.
A function that does not return any data is called a ______ function.
A. void
B. fruitful
C. empty
D. variable
A. void
What is the difference between a parameter and an argument?
A. A parameter cannot be changed in the function, while an argument can be changed.
B. An argument is the data passed into the function when it is called. A parameter is the variable defined in the function header.
C. A parameter is a local variable while an argument is global to the program.
D. They are different words for the same thing.
B. An argument is the data passed into the function when it is called. A parameter is the variable defined in the function header.
Which of the following is NOT true of a void function?
A. They can accept input parameters.
B. A variable assigned to the result of a void function will have a value of None.
C. They do not return values.
D. Since they cannot return data, they cannot perform any data manipulation.
D. Since they cannot return data, they cannot perform any data manipulation.
Which of the following is NOT an example of a function?
A. print
B. int
C. math.sin
D. math.pi
D. math.pi
Which of the following is an example of a Boolean expression?
A. a = a + b
B. a = 10
C. a += b
D. a % b == 2
D. a % b == 2
The keyword True in Python is an example of which of the following?
A. A logical operator.
B. A Boolean.
C. A conditional.
D. An expression.
B. A Boolean.
What type of data results from the last line of the following code:
a += 10
b += 20
a == b
A. A logical operator.
B. A Boolean.
C. An expression.
D. A conditional.
B. A Boolean.
If a recursive function does not have a base case or cannot reach a base case, what will happen?
A. The function will continue to call itself forever until the program crashes.
B. The function will cause a syntax error in the program and the program will never run.
C. The function will continue to call itself until a conditional statement is reached.
D. The function will return a Boolean value after it completes 1000 iterations of the function.
A. The function will continue to call itself forever until the program crashes.
In Python the following keywords are examples of what?
and
or
not
A. Logical operators.
B. Boolean operators.
C. Expressions.
D. Conditional statements.
A. Logical operators.
The Python keyword elif provides what to a program?
A. Forced program termination
B. Logical operators
C. Branching
D. Boolean values
C. Branching
Consider the following:
a is true
b is false
c is true
then which of the following statements is correct?
A. a and b and c is true
B. not b or c is false
C. b and not a is true
D. a and b and c is false
D. a and b and c is false
When an if/else block is fully contained within an if/elif/else statement, this is referred to as ...
A. a chained conditional statement.
B. a compound logical operation.
C. a nested conditional statement.
D. an enhanced Boolean operation.
C. a nested conditional statement.
When a function calls itself this is referred to as ...
A. a nested function call.
B. a recursive function call.
C. an illegal function call.
D. a Boolean function call.
B. a recursive function call
Conditional statements allow which of the following?
A. The ability to convert between data types.
B. Alteration of the program behavior based on data in the program.
C. The saving of Boolean values.
D. Alternative syntax for manipulating variables.
B. Alteration of the program behavior based on data in the program.
Which of the following is NOT a mathematical function that returns a value?
A. math.pi
B. math.log
C. math.isfinite
D. math.degrees
A. math.pi
Which of the following is NOT true of the function isinstance?
A. It can be used to test the type of data a variable currently stores.
B. It is a built in function.
C. It returns a Boolean value.
D. It can determine if data is a numeric type but cannot differentiate between decimal and integer types.
D. It can determine if data is a numeric type but cannot differentiate between decimal and integer types.
When using functions that have return data, which of the following is NOT true?
A. A function that returns data can be used in a mathematical expression.
B. A function that returns data can be used in a conditional statement.
C. A function that returns data cannot be used within another function that returns data.
D. A function that returns data can be used in an assignment statement.
C. A function that returns data cannot be used within another function that returns data.
When a function encounters a return statement, which of the following occurs?
A. The function terminates immediately.
B. The function may continue running if a return value is specified.
C. The function will end and always return a Boolean value.
D. The function will continue running until all the code is executed but will return the value associated with the return statement.
A. The function terminates immediately.
When a return statement is followed by a mathematical expression which of the following is true?
A. The function will run all code contained within it and then calculate the expression and return the value after all other code is completed.
B. The expression will be converted to a Boolean value and returned.
C. The expression will be calculated and the final result will be returned.
D. The expression will be returned from the function and variables in the calling code will be used to produce the final calculation.
C. The expression will be calculated and the final result will be returned.
When using a function that returns data in your program what is required to use the data in the calling code?
A. The data can be stored in a variable but not passed to another function via composition.
B. The data must be passed to another function via composition but cannot be stored in a variable.
C. The result of the function must be captured in a variable or passed to another function via composition.
D. The calling code cannot capture the return value directly.
C. The result of the function must be captured in a variable or passed to another function via composition.
In a function such as the following:
input_data = 20
def evaluate_data(input_data):
if input_data == 10:
return 'You guessed the number.'
else: return 'You guessed wrong.'
What will be returned from the function?
A. The string 'You guessed wrong.'
B. The string 'You guessed the number.'
C. It cannot be determined from the given information.
D. A Boolean value.
C. It cannot be determined from the given information.
In a function such as the following:
def evaluate_data(input_data):
if input_data == 10:
return 'You guessed the number.'
else: return 'You guessed wrong.'
What will be returned from the function?
A. It cannot be determined from the given information.
B. The string 'You guessed wrong.'
C. The string 'You guessed the number.'
D. A Boolean value.
A. It cannot be determined from the given information.
Which of the following is NOT true of a function that returns data?
A. It can return a Boolean value.
B. It may use conditonal logic to return data of different types.
C. It can return a string value.
D. It must accept input data in the form of parameters.
D. It must accept input data in the form of parameters.
Which of the following is NOT true of Boolean functions?
A. The Boolean value can be captured in a variable from the calling code.
B. They must be named in such a way as to answer a yes/no question.
C. They can have multiple return statements but only one return statement can be executed in a given run of the function.
D. They can be used directly in a conditional statement.
B. They must be named in such a way as to answer a yes/no question.
In the following code, what is the final value of total?
total += 1
total = 100
total *= 2
total = total - 20
total + 100 * 5
total += 3
A. 685
B. 183
C. 184
D. 683
E. it cannot be determined from the given data
B. 183
Based on the following code, what is the final value of comparison?
a += 10
b += 20
a = input('Enter a number')
b = 50
test = b <= 50
check = a == b
comparison = test and check
A. it cannot be determined from the given data.
B. this code contains illegal data or syntax errors.
C. false
D. true
C. false
The range in Python creates which of the following?
A. A sequence of numbers.
B. A Boolean value.
C. Two numbers.
D. A number.
A. A sequence of numbers.
The range function accepts a third argument which changes which of the following?
A. The starting value of the sequence.
B. The difference between numbers in the sequence.
C. The final value of the sequence.
D. The number of values to generate.
B. The difference between numbers in the sequence.
Which of the following must happen for a "while" loop to terminate (assuming there is no break statement in the loop)?
A. The loop must produce a mathematical result.
B. The loop condition needs to be altered within the loop body.
C. The loop must produce the proper final data.
D. The loop must complete at least two iterations.
B. The loop condition needs to be altered within the loop body.
If a while loop does not have a proper terminating condition which of the following will occur?
A. A break statement will be implicitly understood to be part of the loop and will terminate it.
B. The loop will drain system resources until the computer crashes.
C. The loop will run forever.
D. The loop will terminate after all the code within the loop body has run.
C. The loop will run forever.
Which is NOT true of the for loop?
A. It will run a number of times.
B. The variable designated in the loop declaration can be used within the loop body.
C. It cannot contain conditional statements.
D. It can contain any number of lines of code.
C. It cannot contain conditional statements.
The "break" keyword is used to...
A. continue a loop.
B. terminate a loop.
C. evaluate the loop body.
D. test a loop to see if it should be run again.
B. terminate a loop.
What is the minimum number of times that a while loop can run?
A. 2
B. infinite
C. 0
D. 1
C. 0
The code immediately following the "while" keyword should be...
A. a Boolean expression.
B. a numeric calculation.
C. a break statement.
D. a function definition.
A. a Boolean expression.
When using the "upper" and "lower" methods of a string, which of the following is true?
A. Parentheses are not required after the keywords "upper" and "lower".
B. An argument will be required.
C. The methods return a new string but do not change the string on which they operate.
D. They will invert the cases of existing characters in the string.
C. The methods return a new string but do not change the string on which they operate.
Which is a valid way to traverse the characters in a string?
A. Using a "while" loop with a counter.
B. Using the "in" operator.
C. Using the "range" function.
D. Using string methods.
A. Using a "while" loop with a counter.
In the following string
"This is a test"
What is the character at index 5?
A. i
B. s
C. a space
D. a
A. i
Which of the following is NOT true of strings in Python?
A. The represent a sequence of characters.
B. The have an index value associated with each character.
C. The value of characters at specific indexes can be reassigned.
D. They can contain zero characters.
C. The value of characters at specific indexes can be reassigned.
When comparing two strings using greater than or less than Boolean expressions, which of the following is true?
A. Strings can only be compared when they are assigned to variables.
B. Lowercase characters are evaluated as coming before uppercase characters.
C. Strings are evaluated based on their length so longer strings are greater than smaller strings.
D. Uppercase characters are evaluated as coming before lowercase characters.
D. Uppercase characters are evaluated as coming before lowercase characters.
Which is a valid way to traverse the characters in a string?
A. Using a conditional expression and the "len" function.
B. Using a counter and a conditional expression.
C. Using a "for" loop.
D. Using the "find" method.
C. Using a "for" loop.
The len function can be used to determine the which of the following about a string?
A. The value of the last index in the string.
B. The number of non-space characters in the string.
C. The number of characters in the string.
D. The number of bits of memory that the string requires.
C. The number of characters in the string.
To traverse a string you could use which of the following Python constructs?
A. A loop.
B. An assignment.
C. A Boolean expression.
D. A conditional.
A. A loop.
The relationship between the value returned by the len function when run on a string and the last index of the string is which of the following?
A. The last index is the value returned by len minus 1.
B. It is dependent on the exact string and cannot be determined for the general case.
C. The last index is the value returned by len plus 1.
D. The last index is the value returned by len.
A. The last index is the value returned by len minus 1.
What is the length of an empty string?
A. -1
B. 0
C. It cannot be determined.
D. 1
B. 0
The plus sign '+' operator performs what task when used on two lists?
A. index shifting
B. concatenation
C. summation
D. addition
B. concatenation
The "is" operator checks which of the following?
A. Whether two lists have the same number of elements.
B. Whether two variables refer to the same object.
C. Whether two variables have equivalent values.
D. Whether two strings have the same value.
B. Whether two variables refer to the same object.
In a list slice, if the second number is omitted, what will be the last index of the sliced data?
A. One more than the first number used in the slice.
B. The second to last index of the list.
C. The last index of the list.
D. The first index of the list.
B. The second to last index of the list.
Which of the following is NOT true of lists in Python?
A. They can contain lists.
B. They can contain mixed data types.
C. They must hold at least one element.
D. The data at any position in the list can be changed.
C. They must hold at least one element.
Which of the following is NOT a list method?
A. append
B. sort
C. remove
D. len
D. len
What is true about using a "for" loop with a "range" to access list items that is not true when a "for" loop is used to loop over the list items directly?
A. You can find the length of the list.
B. You can update the items in the list.
C. You can guarantee that the loop will run at least once.
D. You can print the items from the list.
B. You can update the items in the list.
The "split" method of a string produces which of the following?
A. A list of words.
B. The number of spaces used in the string.
C. The a list of letters.
D. The number of characters used to connect the string.
A. A list of words.
Which is true of two objects that are equivalent?
A. They must be identical.
B. They cannot be identical.
C. They are not necessarily identical.
D. They are lists with the same values.
C. They are not necessarily identical.
The "pop" method returns which of the following?
A. The updated list with the last value removed.
B. The value that was removed from the list.
C. The number of items left in the list.
D. The index of the removed list.
B. The value that was removed from the list.
A reduce operation takes each element in a list and uses it to do which of the following?
A. Combine multiple lists into a single list.
B. Decrease the value at each position in the list.
C. Produce a single value.
D. Update the value at the specified position in the array.
C. Produce a single value.
Which of the following is true of dictionaries in Python?
A. They can be empty (have no keys or values).
B. The value for a key cannot be a list.
C. They can use lists as their keys.
D. They may not be used within a list.
A. They can be empty (have no keys or values).
Which of the following is true of dictionaries in Python?
A. Dictionaries cannot be returned from a function.
B. Dictionaries cannot be passed to a function as an argument.
C. Dictionaries can have multiple keys with different values.
D. Dictionaries cannot have numeric keys.
C. Dictionaries can have multiple keys with different values.
What kind of data is considered "hashable"?
A. all are hashable.
B. integer numbers
C. strings
D. floating point numbers
A. all are hashable.
Which of the following is NOT true of dictionaries in Python?
A. You can retrieve a list of all the keys using the "keys" method.
B. The "get" method will always fail if the element retrieved is not in the dictionary.
C. You can retrieve a list of all the values using the "values" method.
D. The order of key value pairs is not guaranteed.
B. The "get" method will always fail if the element retrieved is not in the dictionary.
A "raise" statement will cause which of the following to occur when it is reached in a program?
A. The function that raised the exception will return False and print an error message.
B. The function that raised the exception will return an error message.
C. The program will halt and print an error message.
D. The program will print an error message but continue to run.
C. The program will halt and print an error message.
To traverse over all the values in a dictionary which of the following techniques could be used?
A. using a "while" loop to print each value based on its numeric index in the dictionary.
B. using a "for" loop with a "range" to print each value based on its numeric index in the dictionary.
C. using a "for in" loop to access each value in the dictionary.
D. using a "for in" loop to access each key and then printing the value associated with the key.
D. using a "for in" loop to access each key and then printing the value associated with the key.
The "sorted" function will do which of the following to a dictionary?
A. Alter the dictionary and convert the keys to a list.
B. Ensure that the keys of the dictionary will always be available in alphabetical order.
C. Alter the dictionary and convert the values to a list.
D. Return a sorted list of the dictionary keys.
D. Return a sorted list of the dictionary keys.
A hash will always return what kind of value?
A. a boolean
B. a floating point number
C. an integer
D. a string
C. an integer
The "in" operator will tell you which of the following about a dictionary?
A. The number of times a value occurs in a dictionary.
B. Whether a key is in a dictionary.
C. Whether a value is in a dictionary.
D. Whether a value in a dictionary contains a list.
B. Whether a key is in a dictionary.
Which of the following best describes the concept of a "memo" in a program?
A. A type of function that returns a dictionary.
B. A technique for improving memory efficiency in a program.
C. A technique for keep track of previously computed values to prevent unnecessary calculation.
D. A type of function that will always produce the same results.
C. A technique for keep track of previously computed values to prevent unnecessary calculation.
The primary difference between a list and a tuple is...
A. Lists are index by number starting at zero but tuples are indexed by number starting at one.
B. tuples can only contain two values while lists can contain any number.
C. Lists are index by number starting at zero but tuples are indexed by strings.
D. tuples are immutable and lists are mutable.
D. tuples are immutable and lists are mutable.
The difference between true random and pseudo-random is that...
A. True random numbers cannot produce repetitive sequences but pseudo-random numbers can.
B. pseudo-random numbers are produced by an algorithm and can be predicted with enough information while random numbers cannot be.
C. It is possible to determine the next pseudo-random number by seeing the ones that came before it. This is not true of random numbers.
D. Random numbers will follow normal statistical distributions while pseudo-random numbers will not.
B. pseudo-random numbers are produced by an algorithm and can be predicted with enough information while random numbers cannot be.
Once an exception is "caught" in your program you can access it by performing which of the following tasks?
A. Assigning it a variable name within the try block.
B. Raising a new exception with a variable name.
C. Assigning it a variable name in the except block.
D. Defining the type of exception you want to catch.
C. Assigning it a variable name in the except block.
In order to persist data between running a program subsequent times which of the following must occur?
A. Data must be converted to a string prior to being saved.
B. Data must be written to working memory (RAM).
C. Data must be written to permanent storage..
D. Data must be stored in a database file.
C. Data must be written to permanent storage..
Relative paths always...
A. should be avoided when writing Python programs.
B. begin from the current directory.
C. being at the root of the computer's file system.
D. throw file system errors when used in a program
B. begin from the current directory.
In order to control errors in a program what technique is used in Python?
A. Writing errors to a database file.
B. Avoiding direct access to the file system.
C. The use of a try/except block.
D. The use of a conditional statement.
C. The use of a try/except block.
A file system path that does not depend on the current directory is called a(n)...
A. operating system path.
B. relative path.
C. current working directory.
D. absolute path.
D. absolute path.
Which of the following is NOT true of tuples?
A. They may be returned from a function.
B. They can be used as the keys in a dictionary.
C. The values in a tuple must be all of the same type.
D. They can be reassigned but the items within them cannot be.
C. The values in a tuple must be all of the same type.
Which of the following is not true of a database file created by the python dbm module?
A. It can be read and written by Python.
B. It can be used to save data between running a program subsequent times.
C. It is a plain text file.
D. Once created it can be opened and written to again.
C. It is a plain text file.
In order to create a function that has an optional arguments you must do which of the following?
A. Only specify the first argument when calling a function.
B. Set a value for the argument when the function is called.
C. Specify a default value for the parameter.
D. Have at least two parameters in the function definition.
C. Specify a default value for the parameter.