Font size
WorksheetsPython Semester 2 Exam Review
Total questions: 52
Worksheet time: 28mins
You have a variable named “True” and Python gives you an error. What’s the problem?
The “T” should be lower-case
“True” is a reserved keyword used by Python
Every letter must be capitalized
It’s correct. There is some other problem in the script
The modulo operator uses what symbol?
**
//
%
^
Python comments are denoted by what symbol?
#
//
/*
$
x = True, y = False
What is the value of the expression not x?
True
False
x = True, y = False
What is the value of the expression y and not x?
True
False
x = True, y = False
What is the value of the expression not x or not y?
True
False
What common Python function is used to display text to the screen?
display
output
show
The (a) data type represents true or false.
Strings are a collection of (a) , such as letters, numbers, or symbols.
True/False: Code blocks are always indented.
(a)
True/False: Else statements do not require an if statement before it.
(a)
True/False: Strings are immutable, which means that they can change.
(a)
True/False: A for loop runs for a certain number of times.
(a)
Observe the following code segment:
num = 4
if num <= 4 and num + 1 != 5:
print("A")
elif num < 4:
print("B")
print("C")
What is the final output?
C
B
A
AB
AC
When using format on a string, which of the following represents a placeholder for a value?
{ }
[ ]
( )
< >
In Python, what do we use to start a code block?
colon
quotes
forward slash
question marks
A Code Block is: (Choose all that apply)
A collection of lines of codes
Always indented
Never indented
Allowed to be typed how the programmer feels works best
What allows code to go down different paths based on Boolean expressions?
Conditional statement
False statement
True statement
Factual statement
What has to happen for an else statement to work properly? (Choose Two)
It has to have an if statement before it.
the condition has to fail.
the condition has to be true.
it takes the place of an if statement.
An if statement checks if something is:
true
false
How many if statements can we put into a code, as long as we are entering them properly?
As many as you want
3
5
1
What does elif mean?
(a)
What best describes an input?
A pause in the function until the user types in something and hits enter.
A section of the program that prints a value.
A pause in the program until the computations are completed.
An area of code that requires the program itself to enter something and hit enter.
Format function allows us to format:
Strings
Integers
Variables
Parameters
An input function will only return what as a variable?
String
Boolean
Float
Integer
What function will show zero or more things that are separated by a comma?
Function
Show
Variable
What do we need to use to show that something is a parameter?
colon
comma
parenthesis
quotes
Which operator means power:
+
-
*
//
**
x=True, y=False
What is the value of the expression: not x
True
False
x=True, y=False
What is the value of the expression: x or y
True
False
Which comparison Operator means not equal to:
!=
=!
==
=/=
What is the main purpose for using Assignment Operators?
Shorthand for longer expressions
Simple Assignment
Assigning a value to the variable
SO MUCH MATH
In Python, there are four groups of operators:
Calculations
Comparison
Assignment
Logical
Answers
A while loop will keep running as long as something is:
True
False
A (a) is a name that refers to a value.
Reserved words, known as keywords, cannot be used for variable names.
True
False
True/False: Function names can start with a digit.
(a)
True/False: Function parameters affect a variables value after the function is complete.
(a)
Given the following function:
def square_number( x ):
return x * x
What does the function call square_number(2+4) return?
4
8
16
36
Consider the following code segment:
x = 7.4
int( x )
print( x )
What is the value of x at the end of this code?
7.4
7
74
7.0
You are creating a function that manipulates floating point values. You have two requirements: the function must take the absolute value of the float, and the value must be rounded up to the nearest integer value. Which two math functions should you use to accomplish this task?
math.abs(x)
math.ceil(x)
math.exp(x)
math.floor(x)
math.mod(x)
Given the following function:
def divide_by_ten( number):
while number / 10 >= 10:
number /= 10
return number
What would the function call divide_by_ten(480) return?
480
80
48
4
What do we call a block of code that performs an action?
Ability
Format
Function
Variable
True/False: Functions can be reused to simplify our programs and prevent us from repeating ourselves.
(a)
What are the elements that make up a function? (Choose all that apply)
Name
Parameters
Return
Value
Format
Some functions have ____ which are values supplied to the function to work.
Parameters
Parenthesis
Strings
Variables
Name the keyword used to define a function.
define
def
function
fu
Which one is not true about function?
It breaks the large program into small modules.
It avoids repetition.
It makes code reusable.
It makes the program unorganized.
You have a function called classes_schedule that returns the class name, period, time of your current schedule. Which of the following statements will return all three of these values?
return science, 1st period, 7:25
return class name & period & time
return class name, period, time
class name + period + time
You cannot return multiple values
Given the following function:
def divide_by_ten( number):
while number / 10 >= 10:
number /= 10
return number
What would the function call divide_by_ten(360) return?
360
36
300
8
You are creating a function that manipulates floating point values.
What functions would I use to get the value of the nearest integer value?
Which two math functions should you use to accomplish this task?
math.abs(x)
math.exp(x)
math.mod(x)
math.ceil(x)
math.floor(x)
Which words cannot be used for variable names? (select all that apply)
Reserved
Keywords
Saved words
Any string
