NEW
Font size
WorksheetsPython Ch 1-3
Total questions: 25
Worksheet time: 2hrs 16mins
Which of the following is NOT a valid name that can be used for a variable?
floater
total
11great
propertyTax
What program is used by a programmer to convert high-level code into executable code?
translator
run-time system
interpreter
text editor
The while loop is also known as what kind of a loop?
infinite loop (Never ends)
exit-controlled (Happens at least once) loop
entry-controlled (May or May Never Happen) loop
count controlled loop(uses a range of values)
What term describes the process of substituting a simple process for a complex process in a program to make the program easier to understand and maintain?
refactoring
abstraction
inheritance
instantiation
What character is used as the format operator when formatting output?
%
" "
\
$
What kind of programming language is Python?
interpreted
compiled
machine
discovered
You are reviewing the code written by another programmer and encounter a variable whose name is entirely in capital letters. What might you discern from this variable name?
title to program
constant value
a variable
a library
In Python, what does the "%" operator do in the expression 10 % 3?
Raises 10 to the power of 3
turns 10 into 0.10 and then multiplies by 3
returns the whole number answer to a division problem
returns the remainder of a division problem
What is a count controlled loop?
It is a loop that counts iterations until a sentinel value is received.
It is a loop that prints out a count of values for the user.
It is a loop that continues based on a certain time interval.
It is a loop that counts through a range of numbers to control when the loop ends.
What part of the loop comprises the statements to be executed?
header
body
end
trailer
What function call will generate a random number in the range of 1 through 6 using the random module?
random.randnum(1, 6)
random.randint(range(1-6))
random.randint(1, 6)
random.random(1, 6)
What must be done in order to concatenate a string and a float object?
Nothing can be done, as the two data types cannot be converted to a compatible type.
The string object must be converted to a float object via the float() function.
The float object must be converted to an integer object via the int() function.
The float object must be converted to a string object via the str() function.
Given the following statement: "%4d" % var1, which of the following is accurate?
The variable var1 must be an integer value.
The variable var1 must be a string value.
The variable var1 will be in octal format.
The variable var1 will be formatted regardless of type.
In general terms, what does a selection statement do?
It forces a computer to favor one value over another.
It allows a computer to make choices based on test conditions.
It allows a computer to select the values that are most economical.
It allows a computer to selectively execute based on processing cost.
When attempting to produce a correct program, what is the point of developing a test suite?
To provide a small set of inputs as a test to verify that a program will be correct for all inputs.
To modify the running program's variables and verify that the program will still function, even if the code changes.
To test the outputs of a program against known values to verify that the math coprocessor is performing properly.
To test the code syntax for possible errors such as undefined variables.
At what point in the interpretation of a Python program are syntax error messages generated?
After the conversion of the code into byte code.
Before execution of the program, when it is passed through the translator.
During execution of the program by the Python virtual machine.
After user input defined by the program is collected.
How does the int function convert a float to an int?
By rounding to the nearest whole number.
By removing the fractional value of the number.
By rounding up to the closest whole number.
By rounding down to the closest whole number.
When a Python interpreter runs a script, what is the script translated into?
assembly code
byte code
interpolated language code
high level language code
What is a one-way selection statement in the context of Python?
It is a single if statement without a corresponding else statement used to test a condition and run statements, then proceed to the next statement.
It is a single if-else statement block that is used to test a condition and run statements, as well as provide a default path for execution.
It is a switch statement block that is used to direct the flow of data based on a single condition.
It is an if statement that tests no conditions, but provides a block for execution.
You are working on a Python script that relies heavily on the cos and sin functions of the math module. As these are the only functions you require, what should you do to import only these functions, rather than the whole math module?
import cos, sin
import cos, sin from math
import math.cos, math.sin
from math import cos, sin
What is the value of string1 after the following statement is executed?
string1 = "hello"[:3] + "python"[0]
lpython
llo
help
lop
What is the output of the following code? EACH { is a tab -- tab will not format)
sum = 0
for value in range(1,4):
{
if value == 2:
{
sum = sum**2
sum += value
}
}
print(sum)
6
12
8
16
What is the output of the following code? { represents a tabbed section
sum = 0
value = 3
while value <= 5:
{
sum += value
value += 1
}
print(sum)
15
10
12
18
11001100 = ___________ base 10
204
314
8
208
78 = _________________ Base 2
01001110
001101110
00011111
10101011
