Python Study Set
In Python the ________ symbol is used as the not-equal-to operator.
!=
Which mode specifier will open a file but not let you change the file or write to it?
'r'
Which mathematical operator is used to raise 5 to the second power in Python?
**
What are the values that the variable num contains through the iterations of the following for loop? for num in range(2, 9, 2):
2, 4, 6, 8
What is the output of the following command, given that value1 = 2.0 and value2 = 12? print(value1 * value2)
24.0
What is the largest value that can be stored in one byte?
255
After the execution of the following statement, the variable price will reference the value ________. price = int(68.549)
68
Which of the following is not an augmented assignment operator?
<=
In Python the ________ symbol is used as the equality operator.
==
Which of the following is the correct if clause to determine whether choice is anything other than 10?
??? look up
The ________ coding scheme contains a set of 128 numeric codes that are used to represent characters in the computer's memory.
ASCII
A variable used to keep a running total is called a(n)
Accumulator
A(n) ________ is any piece of data that is passed into a function when the function is called.
Argument
The smallest storage location in a computer's memory is known as a
Bit
What type of function can be used to determine whether a number is even or odd?
Boolean
A(n) ________ structure is a logical design that controls the order in which a set of statements execute.
Control
Which of the following is considered to be the world's first programmable electronic computer?
ENIAC
In a print statement, you can set the ________ argument to a space or empty string to stop the output from advancing to a new line.
End
A while loop is called a pretest loop because the condition is tested after the loop has had one iteration.
False
All programs are normally stored in ROM and are loaded into RAM as needed for processing. T/F
False
If a file with the specified name already exists when the file is opened and the file is opened in 'w' mode, then an alert will appear on the screen. T/F
False
In Python, there is nothing that can be done if the program tries to access a file to read that does not exist.
False
One of the drawbacks of a modularized program is that the only structure you can use in such a program is the sequence structure. T/F
False
Python allows the programmer to work with text and number files.
False
Python allows you to compare strings, but it is not case sensitive.
False
Python formats all floating-point numbers to two decimal places when outputting with the print statement. T/F
False
Python uses the same symbols for the assignment operator as for the equality operator. T/F
False
The Python language is not sensitive to block structuring of code.
False
The first line in a while loop is referred to as the condition clause.
False
The not operator is a unary operator which must be used in a compound expression. T/F
False
The sort method rearranges the elements of a list so they are in ascending or descending order. T/F
False
To add a descriptive label to the X and Y axes of a graph when using the matplotlib package, you need to import the labels module. T/F
False
Unfortunately, there is no way to store and call on functions when using turtle graphics. T/F
False
When a piece of data is read from a file, it is copied from the file into the program. T/F
False
The process known as the ________ cycle is used by the CPU to execute instructions in a program
Fetch-decode-execute
After the execution of the following statement, the variable sold will reference the numeric literal value as (n) ________ data type. sold = 256.752
Float
Which of the following functions returns the largest integer that is less than or equal to its argument?
Floor
A(n) ________ is a diagram that graphically depicts the steps that take place in a program?
Flowchart
What is the output of the following print statement? print 'I\'m ready to begin'
I'm ready to begin
Where does a computer store a program and the data that the program is working with while the program is running?
In main memory
What does the following program do? student = 1 while student <= 3: total = 0 for score in range(1, 4): score = int(input("Enter test score: ")) total += score average = total/3 print("Student ", student, "average: ", average) student += 1
It accepts 3 test scores for each of 3 students and outputs the average for each student.
What does the following program do? import turtle def main(): turtle.hideturtle() square(100,0,50,'blue') def square(x, y, width, color): turtle.penup() turtle.goto(x, y) turtle.fillcolor(color) turtle.pendown() turtle.begin_fill() for count in range(4): turtle.forward(width) turtle.left(90) turtle.end_fill() main()
It draws a blue square at coordinates (100, 0), 50 pixels wide, in the lower-left corner.
The following is an example of an instruction written in which computer language? 10110000
Machine Language
The Python standard library's ________ module contains numerous functions that can be used in mathematical calculations.
Math
What will be the output after the following code is executed? import matplotlib.pyplot as plt def main(): x_crd = [0, 1 , 2, 3, 4, 5] y_crd = [2, 4, 5, 2] plt.plot(x_crd, y_crd) main()
Nothing; the number of x-coordinates do not match the number of y-coordinates.
What will be the output after the following code is executed and the user enters 75 and -5 at the first two prompts? def main(): try: total = int(input("Enter total cost of items? ")) num_items = int(input("Number of items ")) average = total / num_items except ZeroDivisionError: print('ERROR: cannot have 0 items') except ValueError: print('ERROR: number of items cannot be negative') main()
Nothing; there is no print statement to display average. The ValueError will not catch the error.
Which step creates a connection between a file and a program?
Open the file
The first operation is called the ________ and its purpose is to get the first input value that will be tested by the validation loop.
Priming read
What is an advantage of using a tuple rather than a list?
Processing a tuple is faster than processing a list.
What is the informal language, used by programmers use to create models of programs, that has no syntax rules and is not meant to be compiled or executed?
Pseudocode
Programs are commonly referred to as
Software
Python comes with ________ functions that have already been prewritten for the programmer.
Standard
Which of the following describes what happens when a piece of data is written to a file?
The data is copied from a variable in RAM to a file.
Which of the following is associated with a specific file and provides a way for the program to work with that file?
The file object
Which of the following is not a major component of a typical computer system?
The operating system
What is the output of the following print statement? print('The path is D:\\sample\\test.')
The path is D:\sample\test.
A flowchart is a tool used by programmers to design programs. T/F
True
Computer programs typically perform three steps: input is received, some process is performed on the input, and output is produced. T/F
True
IDLE is an alternative method to using a text editor to write, execute, and test a Python program. T/F
True
In Python, print statements written on separate lines do not necessarily output on separate lines. T/F
True
In a flowchart, both the decision structure and the repetition structure use the diamond symbol to represent the condition that is tested.
True
In a nested loop, the inner loop goes through all of its iterations for each iteration of the outer loop. T/F
True
In order to create graphs using the matplotlib package, you need to import the pyplot module.
True
In slicing, if the end index specifies a position beyond the end of the list, Python will use the length of the list instead.
True
Lists are dynamic data structures such that items may be added to them or removed from them. T/F
True
Nested decision statements are one way to test more than one condition. T/F
True
Python function names follow the same rules as those for naming variables. T/F
True
RAM is a volatile memory used for temporary storage while a program is running. T/F
True
Reducing duplication of code is one of the advantages of using a loop structure. T/F
True
The CPU understands instructions written in a binary machine language. T/F
True
The following code snippet will change the turtle's pen size to 4 if it is presently less than 4: T/F if turtle.pensize() < 4: turtle.pensize(4)
True
The function header marks the beginning of the function definition.
True
The if statement causes one or more statements to execute only when a Boolean expression is true. T/F
True
The instruction set for a microprocessor is unique and is typically understood only by the microprocessors of the same brand. T/F
True
To assign a value to a global variable in a function, the global variable must be first declared in the function. T/F
True
Which list will be referenced by the variable number after the following code is executed? number = range(0, 9, 2)
[0, 2, 4, 6, 8]
What will be the value of the variable list2 after the following code executes? list1 = [1, 2, 3] list2 = [] for element in list1: list2.append(element) list1 = [4, 5, 6]
[1, 2, 3]
A value-returning function is
a function that will return a value back to the part of the program that called it
Which statement can be used to handle some of the runtime errors in a program?
a try/except statement
When using the ________ logical operator, both subexpressions must be true for the compound expression to be true.
and
A set of statements that belong together as a group and contribute to the function definition is known as a
block
What type of loop structure repeats the code based on the value of Boolean expression?
condition-controlled loop
What type of loop structure repeats the code a specific number of times?
count-controlled loop
What will be displayed after the following code is executed? count = 4 while count < 12: print("counting") count = count + 2
counting counting counting counting
A single piece of data within a record is called a
field
Which of the following will determine if the turtle's pen is up and will change it to down if that is the case?
if not(turtle.isdown()): turtle.pendown()
Which of the following will hide the turtle if it is visible?
if turtle.isvisible(): turtle.hideturtle()
The ________ built-in function is used to read a number that has been typed on the keyboard.
input()
Which method can be used to convert a tuple to a list?
list
Which of the following will assign a random integer in the range of 1 through 50 to the variable number?
number = random.randint(1, 50)
Which of the following is the correct way to open a file named users.txt to write to it?
outfile = open('users.txt', 'w')
Which of the following will display 20%?
print(format(0.2, '.0%')) <enter>
Which type of file access jumps directly to a piece of data in the file without having to read all the data that comes before it?
random
Which method could be used to strip specific characters from the end of a string?
rstrip
The ________ of a local variable is the function in which that variable is created.
scope
Which type of error prevents the program from running?
syntax
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
Which of the following 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
How many types of files are there?
two
What does the following expression mean? x <= y
x is less than or equal to y