WorksheetsPython CH1-3 Review
Total questions: 59
Worksheet time: 36mins
Which of the following are ways you can run a Python program?
Double clicking on the file directly
Opening the file in IDLE and clicking “Run Module”
Running the program through Command Prompt or terminal
All the above
What is the file extension used for Python scripts?
.py
.p
.python
.ps
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
x = True, y = False
What is the value of the expression not( x and y )?
True
False
Which of the following is the proper way to write the string: “Hello, world!”?
A. "Hello, world!"
B. 'Hello, world!'
C. "Hello, world!'
Both A & B
A, B, and C
What common Python function is used to display text to the screen?
display
output
show
You have the following line in your script:
number_of_apples = number_of_apples + 1
How would you rewrite this expression in shorthand?
number_of_apples++
number_of_apples += 1
number_of_apples =+ 1
number_of_apples+1
What is the convention for naming a constant?
Write it in all capital letters
Capitalize the first letter
Start the name with const_
Start it with a dollar sign
Observe the following code:
word1 = "hello" word2 = "world" string = word1 + word2 * 2
What is the value of variable string?
(A ‘_’ represents a space)
helloworld
hello_world_world
helloworldworld
helloworldhelloworld
The (a) data type represents true or false.
If a variable name uses multiple words, you should separate them using underscores or write it in (a) .
Strings are a collection of (a) , such as letters, numbers, or symbols.
(a) is where you convert a value to a different data type, such as an integer to a float.
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)
You are trying to get an integer from the user’s input and save it to the variable x. Which of the following will accomplish the task?
x = input("Enter a number: ")
x = int(input("Enter a number: ")
Both A & B
Neither A nor B
Which of the following can be used to represent a multi-line string? Select all that apply.
"
""
"""
'''
Observe the following line of code:
string = "No one expects... ____ the Spanish inquisition!"
Which escape sequence will correctly put a line-break where the “____” is?
\n
\nl
\lb
\r
Observe the following code segment:
x = 0 while x <= 10:
print(x) x += 2
How many times will the while loop run?
5
6
10
11
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
Observe the following incomplete code segment:
string = "Hello, world!"
___________________:
print(letter)
You are wanting to print each letter of string on its own line. Which of the following statements would correctly do this if put on the blank line?
for letter in string
for string as letter
while letter in string
while letter != len(string)
When using format on a string, which of the following represents a placeholder for a value?
{ }
[ ]
( )
< >
Observe the following code segment:
for x in range(__,__):
print(x)
What two values (starting and finishing) for range would cause the loop to iterate exactly ten times? Select all that apply.
0, 10
1, 11
0, 9
0, 11
(a) gets a portion of a string; also called a substring.
Observe the following code:
strA = "Hello"
strB = "World"
strC = strA + strB * 3
x = len(strC)
What is the value of x at the end of execution?
5
10
20
25
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 wok 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
If I am formating a string, how do I align the text to the center:
{:<n}
{:^n}
[:^n]
{:n}
If I am formating for percision, which means how many spaces tshould the text take up, I will use:
{:n}
{:.nf}
[:n]
{:<n}
An input function will only return what as a variable?
String
Boolean
Float
Integer
What are two special parameters mentioned today?
sep
end
start
quotes
Sep will allow you to:
Print values between each item.
Specify which item will be at the end.
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
True/False: Make sure your whitespace is used sparingly, only use it to really show what the string is doing.
(a)
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
What comes installed with Python?
IDLE
IDOL
VMware
Nothing
