WorksheetsPython - Syntax, Functions and Control Flow
Total questions: 28
Worksheet time: 14mins
What happens when running the following code?
"message" is printed.
"What a cool message!" gets printed to the console.
Python throws a SyntaxError because the string is not surrounded by quotes.
How does one define a multi-line string in Python?
***
Like
This
***
"""
Like
This
"""
###
Like
This
###
Which of the following defined variables is a string?
cool_variable_1
cool_variable_2
cool_variable_3
cool_variable_4
Which function outputs text to the terminal?
print()
write()
type()
output()
Which of the following will produce a SyntaxError?
What is the difference between a float and an int?
A float can only be used with whole numbers. An int can be any number with a decimal point.
A float contains text information. An int is any number.
A float represents decimal quantities. An int represents whole numbers.
How do you combine two strings?
string1.concatenate(string2)
string1.combine(string2)
string1 + string2
What is Python syntax for creating a variable and setting it equal to the number 10?
def variable_name = 10
variable_name == 10
new variable_name = 10
variable_name = 10
What is the output of the following code?
210
42
cool_number
What number is saved to exponented_variable in the following expression?
8
16
6
24
What character begins a comment in Python?
%
#
*
@
What is the value of total_cost that gets printed?
5
15
10
50
What is the value of modulo_variable in the following expression?
56
2
3.5
14.4
What happens when you call report?
Two Strings are printed: "The current time is " and "The mood is "
One String is printed: "The current time is 3pm"
Two Strings are printed: "The current time is 3pm" and "The mood is good"
Three Strings are printed: "The current time is 3pm", "The mood is good", and "End of report"
Which variables can be called in the blank spot in this code:
Just new_counter
Just counter
counter and new_counter
Neither counter nor new_counter
What line of code can be used to return a variable inner_var from a function back to the piece of code that called the function?
def inner_var
print(inner_var)
inner_var = None
return inner_var
How do you call a function called setup with no arguments?
setup()
setup(None)
def setup():
setup
How do you call update with a new_value of 20?
def update(20)
update(20)
update
update()
What line of code will call force with a value of 10 for mass and a value of 9.81 for acceleration?
force(mass=10, 9.81)
force(9.81, 10)
force(10, mass=9.81)
force(10, 9.81)
Given the following function, what will produce the output "There is no greater agony than bearing an untold story inside you."?
def quote("an untold story")
quote()
quote("an untold story")
quote(an untold story)
Which of the following variables contains a Boolean value?
Which of the following is a Boolean expression?
This quiz is very hard.
Three is the most elegant number.
The New York Yankees are the classiest baseball team.
My name is Angelo.
Determine the truth value of the following expressions:
A: False
B: True
A: False
B: False
A: True
B: True
A: True
B: False
Determine the truth value of the following expressions:
A: True
B: True
A: False
B: True
A: False
B: False
A: True
B: False
Consider the code. What would this print to the terminal?
Nothing is printed.
Is this printed?
Is this printed?
This might be printed.
This is printed.
This is also printed.
What will the code print when it is executed?
result
A ValueError occurred.
A ZeroDivisionError occurred.
A NameError occurred.
Determine the truth value of the following expressions:
A: True
B: False
A: True
B: True
A: False
B: False
A: False
B: True
Read the following code carefully. What will happen when the code is executed?
"x is equal to zero" will print to the terminal.
There will be a ValueError.
"x is equal to zero" and "x is greater than zero" will print to the terminal.
There will be a SyntaxError.
