NEW
Font size
WorksheetsCodeCademy - Python 3 - Syntax and Functions
Total questions: 50
Worksheet time: 27mins
Which of the following is used in Python to calculate ten squared?
Which of the following is an advantage of using local variables?
They allow the variable to be used throughout the whole program
They allow variable identifiers to be reused each time
They are easier to program than global variables
A wider range of data types can be used
What term is used to describe data passed into/out of a program?
function
Loop
Constant
Parameter
Leo wants to create a subroutine that will roll a dice. Which syntax is correct?
def dice roll ():
def diceroll ()
def diceroll ():
def diceroll []:
What will be the output of this program if the user enters "Han" and then "Solo"?
An error
Nothing
first surname
Han Solo
Which of the following best describes the order in which these lines are processed in Python?
4, 1, 2
4, 2, 1
1, 2, 3, 4
3, 1, 2
Are Double or single quotes used in Python?
Double
Single
Neither
Both work
What is wrong with, 'print(x+hello)'
There are too many characters
Print is not a statement in Python
The text is not in quotes
Text cannot be added in python
Which of the following assign the value 50 to a variable x?
x=50
Let x=50
x;=50
x<<50
what does '%' do?
Delete everything
Add to numbers
Find the percentage of the variable to another
Find the remainder after the division of two variables
The program snippet above is syntactically correct
False
True
You should be at least 18 years to vote. What should be the expression in the if statement that will print
can vote.
age >= 18
age = 18
age == 18
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.
Which of the following defined variables is a string?
cool_variable_1
cool_variable_2
cool_variable_3
cool_variable_4
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.
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 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"
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.
What is the output of the following python code?
13
10
2
5
What is the output of the following python code?
error
hello
16
16
hello
What is the output of the following python code?
x=100
def f1():
global x
x=90
def f2():
global x
x=80
print(x)
100
90
80
error
What does the following code do? myAge = int (myAge)
Converts the var (variable) myAge to a string
Converts the var (variable) myAge to a integer
Converts the var (variable) myAge from a integer to a string
Converts the var (variable) myAge to if statement
