Python Midterm QC Questions
what expression would determine if a is not less than b
a >= b
T or F: the not operator requires two operands
false - the not operator only has one operand
T or F: The expression x ^ y raises the value x to the power y.
false - the python exponentiation operator is **
T or F: A turtle draws a filled circle using the fill_circle command
false - there is no such turtle command
the print statement is a call to _____
function
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'
what is syntax coloring
showing certain elements of program code in different colors
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)
What operator is used to perform string concatenation in Python?
+
What is the result of the expression math.pow(3, 3)?
27
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
3
What is the result of the expression 43 % 5?
3
What is the Python programming language named after
the monty python comedy group
T or F: all python variables are object references
true
can an if statement have both an elif and an else clause?
yes - an else clause is often used after a series of elif clauses
If a variable called business refers to the string 'Time Warner', what is the result of the expression business[6]?
'a'
If a variable called word refers to the string 'committee', what is the result of the expression word.strip('m')?
'committee'
If a variable called son refers to the string 'Justin', what is the result of the expression son[-3]?
't'
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
What is the result of the expression math.floor(12.843)?
12
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
If a variable called address refers to the string '123 Main Street', what is the result of the expression address.find('3')?
2
what is the result of the expression 7 // 2
3
What output is produced by the following code? print(15 + 30)
45
2 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
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
what value is assigned to the variable num by the following statement if the current value of num is 4? num = num * 2
8
If a variable called user_id refers to the string 'AEinstein12', what is the result of the expression user_id.isalpha()?
False - the isalpha method returns true only if all characters in the string are alphabetic
Who developed the Python Programming language
Guido van Rossum
What output is produced by the following code? print('Jan', 'Feb', 'Mar', sep='-')
Jan-Feb-Mar
What output would be produced when the following code is executed? state = 'Mississippi' print(state.replace('is', 'was'))
Mwasswassippi
What output does the following code produce? print('Ready', end=' ') print('Set', end='') print('Go')
Ready SetGo
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 or F: Python is a general-purpose programming language, appropriate for solving problems in many areas of computing.
True
T or F: The output of a Python program run in Thonny appears in the shell window.
True
T or F: you cannot change the contents of Python character string once it has been created
True - python strings are immutable
If a variable called jedi refers to the string 'Yoda', what is the result of the expression jedi * 3?
YodaYodaYoda
What is the python standard library?
a collection of programming components that can be used in any Python program
flowchart
a graphical representation of the logic of an algorithm
natural language
a language that humans use to communicate, such as english or french
pseudocode
a language that is independent of any particular programming language
What issue must be addressed when printing a long character string?
a regular string literal cannot span across multiple lines
algorithm
a step-by-step procedure for solving a problem
What is the python shell?
a window in which python statements and expressions are executed immediately
What are Python variables created using?
an assignment statement
What output does the following code produce? print('apple', 'banana')
apple banana
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)
T or F: A Python program must compiled into an executable form before it can be run.
false - python programs are interpreted, executing the code line by line until the end or it encounters an error
Of the options given, what values of the variables height, size, and width would cause the following code to set the variable weight to 100? if height < size: weight = 50 if width < 20: print('short') else: if width > 100: weight = 100 println('tall')
height = 15, size = 10, width = 110
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 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
is python 3 backwards compatible to python 2
no
does the goto command move the turtle without drawing a line?
no - if the pen is down, it will draw a line
does the pass statement have an effect on the program state?
no - it doesn't compute anything or change the value of any variables
If both operands to the remainder operator are positive, will a divisor of produce a result in the range 1 to n
no - it will produce a result in the range 0 to n-1
Does a python function have to have at least on parameter?
no - some functions have no parameters
do the arithmetic operators have a lower precedence than the relational operators
no - the arithmetic operators have a higher precedence than the relational operators. All math will be done before the comparison
Are all mathematical functions in Python are part of the math module
no - there are several built-in functions that perform mathematical operations
do the stroke and fill color of a turtle shape have to be the same color?
no - they can be different
Is a return statement always the last statement in a function?
no - this is often the case, but is not required
Does the effect of the setheading depend on the current heading of the turtle?
no - when setting the heading explicitly, the current heading doesn't matter
will the input function produce an error if the value read is not numeric?
no - you can input numbers, words, symbols, etc.
What does the following code produce? print('Total: ' + 100 + 20)
no output - this line would produce an error because you can't concatenate a string and an integer in Python
Does a python program have to be enclosed in curly braces to be executed?
no they do not have to be enclosed by anything
If A is false, is the B operand in the expression A and B evaluated?
no, since A is false, the truth value of the second operand in an and operation is irrelevant
is the assignment statement also an expression?
no, the assignment operator does not return a value
does the assignment operator have higher precedence than the arithmetic operators?
no, the assignment operator has a lower precedence than the arithmetic operators
Does the input function convert the user input to an integer?
no, the input function always returns the read data as a character string
does the value assigned to a variable have to be numeric?
no, the value can be one of several non-numeric types, such as a character string
Will running a program that contains errors cause the Thonny development environment to terminate?
no, your program will terminate, but Thonny will not
What output is produced by the following code? print('oak', 'elm', 'pine', end='!', sep='#')
oak#elm#pine!
What programming paradigms does python embody elements of
procedural programming, object-oriented programming, and functional programming
What is text that requests user input called?
prompt
where is the origin point (0,0) of the turtle coordinate system?
the center of the screen
input
the data needed by an algorithm to accomplish its task
output
the data produced by an algorithm
What does the term case sensitive mean?
the difference between uppercase and lowercase letters matter
granularity
the level at which an instruction is expressed
how is the body of an if statement separated from the rest of the code
the statements in the body of an if my be indented
T or F: The pen color and size determines the color and width of the lines drawn.
true
T or F: Thonny displays code using syntax highlighting
true
what does setting the turtle's speed to 0 do?
turns off the animation of the turtle movement completely. At that speed the turtle "jumps" forward to each new position
Which way would the turtle be facing after executing the command turtle.setheading(135)?
up and left (northwest)
can built-in functions of the Python standard library be used without being imported
yes
can the value of a variable be changed throughout a program?
yes
can the result of a relational operator be assigned to a bariable
yes - a variable can store a True or False value
can you use relational operators to put character strings in alphabetical order
yes - although differences between uppercase and lowercase letters have to be taken into account
if either or both operands to the division operator are floating point values, will the result be a floating point value?
yes - and if both are integers, it performs integer division
can a character string be used as the condition of an if statement?
yes - any object can be used as a condition. an empty string evaluates to false and any other string evaluates to true
If a filled shape drawn by a turtle is not fully enclosed, does Python fill the shape as if the starting point is connected to the end point?
yes - but the stroke will not be shown for the connecting line
doe the math module contain a constant that represents the value pi?
yes - it also has other constants
does the position of a circle depend on the current heading of the turtle?
yes - the circle is drawn to the left of the turtle
can you use the turtle circle command to draw a regular polygon
yes - the option parameter steps determines how many sides the approximating polygon will have
are the input, int, and float functions all built-in functions?
yes - you dont have to import them
do relational operators all return boolean results?
yes they all produce a result of True or False
could the value assigned to a variable be a floating point number?
yes, both integers and floating point numbers can be stored in variables