CS midterm
Which of the following hex strings represents the color white?
'#FFFFFF'
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 son refers to the string 'Justin', what is the result of the expression son[-3]?
't'
What operator is used to perform string concatenation in Python?
+
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
what is not a valid python identifier
1stPlace (an identifier cannot begin with a digit)
What is the result of the expression math.pow(3, 3)?
27
What is the result of the expression 43 % 5?
3
What is the result of the expression 7 // 2?
3
What output is produced by the following code? print(15 + 30)
45
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?
6
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 count is 2, what value will be stored in count after the following line of code is executed? count += count * 3
8
What value is assigned to the variable num by the following statement if the current value of num is 4? num = num * 2
8
What is the Python Standard Library?
A collection of programming components that can be used in any Python program
Which of the following does the input function NOT do when it is called?
Convert the user input to an integer
All mathematical functions in Python are part of the math module.
False
In dynamically typed languages, variables are declared to store a specific type of data.
False
The assignment operator has higher precedence than the arithmetic operators.
False
The effect of the setheading depends on the current heading of the turtle.
False
The stroke color of a filled turtle shape must be the same as the fill color.
False
The value assigned to a variable must be numeric.
False
The webcolors module is part of the Python Standard Library.
False
Python variables that represent integers are NOT object reference variables.
False (All python variables are object references)
The Python programming language was so named after a snake was discovered in the creator's office.
False (It was named after the Monty Python comedy group)
Python 3 is backwards compatible Python 2
False (Python 2 code will not necessarily run in a Python 3 environment)
Python represents a color using the CMYK color model.
False (RGB color model)
A Python program must be enclosed in curly braces { } to be executed.
False (a single statement is a complete program)
Using components from the Python Standard Library is a rare occurrence.
False (any useful python program will rely on the standard library
In Python, the assignment statement is also an expression.
False (assignment operator does not return a value)
The goto command moves the turtle without drawing a line.
False (it will draw if the pen is down)
If both operands to the remainder operator (%) are positive, a divisor of n will produce a result in the range 1 to n.
False (it will produce a result in the range 0 to n-1)
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)
The expression x ^ y raises the value x to the power y.
False (the exponentiation operator is **)
You must use a print statement to display the result of an expression in the Python shell.
False (the expression is evaluated and the result is displayed immediately)
The origin point (0, 0) of the turtle coordinate system is in the upper left corner of the graphic screen.
False (the origin is the center of the screen)
A turtle draws a filled circle using the fill_circle command.
False (there is no such turtle command)
Running a program that contains errors will cause the Thonny development environment to terminate.
False (your program will terminate, but Thonny will not)
Who developed the Python programming language?
Guido van Rossum
Thonny is best described as
Integrated Development Environment (IDE)
What output is produced by the following code? print('Jan', 'Feb', 'Mar', sep='-')
Jan-Feb-Mar
What output does the following code produce? print('Total: ' + 100 + 20)
No output. This line would produce an error. You can't concatenate a string and an integer in Python
Python embodies elements of which programming paradigm?
Procedural, object-oriented, and functional programming
What output does the following code produce? print('Ready', end=' ') print('Set', end='') print('Go')
Ready SetGo
What is syntax coloring
Showing certain elements of program code in different colors
What does the term case sensitive mean?
The difference between uppercase and lowercase letters matter.
What issue must be addressed when printing a long character string?
The regular string literal cannot span across multiple lines
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
Built-in functions of the Python Standard Library can be used without being imported.
True
If a filled shape drawn by a turtle is not fully enclosed, Python fills the shape as if the starting point is connected to the end point.
True
If either or both operands to the division operator (//) are floating-point values, then the result will be a floating-point value.
True
Python is a general-purpose programming language, appropriate for solving problems in many areas of computing.
True
Python variables are created using an assignment statement.
True
The Python shell has an integrated help system.
True
The Python shell is great for exploring Python language features.
True
The Python turtle graphics module is based on the programming language Logo developed in the 1960s.
True
The human eye has three types of color receptors that correspond to wavelengths of red, green, and blue.
True
The math module contains a constant that represents the value pi to several digits.
True
The math.pi constant represents pi to 15 decimal places.
True
The output of a Python program run in Thonny appears in the shell window.
True
The turtle circle command can be used to draw a regular polygon.
True
The value assigned to a variable could be a floating point number.
True
Thonny has a package manager that lets you install and update external Python packages.
True
You can store a value in a variable in the Python shell.
True
You cannot change the contents of Python character string once it has been created.
True
The position of a circle depends on the current heading of the turtle.
True (circle is drawn to the left of the turtle
Setting the turtle's speed to 0 turns off the animation of the turtle movement completely.
True (the turtle jumps forward to each new position
If a variable called jedi refers to the string 'Yoda', what is the result of the expression jedi * 3?
YodaYodaYoda
What is the Python shell?
a window in which Python statements and expression are executed immediately
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)
the print statement must be the first statement in a python program
false
the print statement sends text output to the editor
false (The print statement prints a line of output to the system output window, which is also called the console window.)
The input function will produce an error if the value read is not numeric.
false (it's type conversions that will produce an error if necessary)
Equal contributions of the three components in an RGB color results in various shades of what?
gray
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 is the correct convention for naming Python variables
lowercase letters with underscores to separate words
What output is produced by the following code? print('oak', 'elm', 'pine', end='!', sep='#')
oak#elm#pine!
What is text that requests user input called?
prompt
Complex is better than complicated
true
Explicit is better than implicit.
true
Full documentation about the Python Standard Library can be found online.
true
Simple is better than complex.
true
The input function always returns the read data as a character string.
true
The input, int, and float functions are all built-in functions.
true
The pen color and size determines the color and width of the lines drawn.
true
The print statement is a call to function
true
The value of a variable can change throughout a program.
true
Thonny displays code using syntax highlighting.
true
beautiful is better than ugly
true
readability counts
true
Which way would the turtle be facing after executing the command turtle.setheading(135)?
up and left (northwest)
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)
Which of the following is NOT a principle embraced by the Python programming language?
verbose is better than succinct