wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

CodeCademy - Python 3 - Syntax and Functions

Total questions: 50

Worksheet time: 27mins

Name
Class
Date
1.
used to structure code in Python
a)
whitespace
b)
comments
c)
booleans
d)
variables
2.
Used to create exponents
a)
**
b)
"""
c)
%
d)
#
3.
stores a piece of data, and gives it a specific name
a)
variable
b)
whitespace
c)
interpreter
d)
modulo
4.
returns the remainder from division
a)
modulo
b)
exponments
c)
boolean
d)
variables
5.
surrounds multi-line comments
a)
"""
b)
**
c)
#
d)
%
6.
a line of text that Python won't try to run as code
a)
comment
b)
modulo
c)
variable
d)
boolean
7.
symbol used for modulo
a)
%
b)
&
c)
#
d)
**
8.
Used to make comments
a)
#
b)
%
c)
**
d)
()
9.
The correct way to write a variable in Python?
a)
my_variable = 10
b)
my variable = 10
c)
my_variable is 10
d)
my_variable: 10
10.
10= 100
Which of the following is used in Python to calculate ten squared?
a)
10 ** 2
b)
10 * 2
c)
10 % 2
d)
10 ** 10
11.

Which of the following is an advantage of using local variables?

a)

They allow the variable to be used throughout the whole program

b)

They allow variable identifiers to be reused each time

c)

They are easier to program than global variables

d)

A wider range of data types can be used

12.

What term is used to describe data passed into/out of a program?

a)

function

b)

Loop

c)

Constant

d)

Parameter

13.

Leo wants to create a subroutine that will roll a dice. Which syntax is correct?

a)

def dice roll ():

b)

def diceroll ()

c)

def diceroll ():

d)

def diceroll []:

14.

What will be the output of this program if the user enters "Han" and then "Solo"?

a)

An error

b)

Nothing

c)

first surname

d)

Han Solo

15.

Which of the following best describes the order in which these lines are processed in Python?

a)

4, 1, 2

b)

4, 2, 1

c)

1, 2, 3, 4

d)

3, 1, 2

16.

Are Double or single quotes used in Python?

a)

Double

b)

Single

c)

Neither

d)

Both work

17.

What is wrong with, 'print(x+hello)'

a)

There are too many characters

b)

Print is not a statement in Python

c)

The text is not in quotes

d)

Text cannot be added in python

18.

Which of the following assign the value 50 to a variable x?

a)

x=50

b)

Let x=50

c)

x;=50

d)

x<<50

19.

what does '%' do?

a)

Delete everything

b)

Add to numbers

c)

Find the percentage of the variable to another

d)

Find the remainder after the division of two variables

20.
What will print ?
a)
cats eat mice
b)
mice get away
c)
unknown
d)
error message
21.

The program snippet above is syntactically correct

a)

False

b)

True

22.

You should be at least 18 years to vote. What should be the expression in the if statement that will print


can vote.

a)

age >= 18

b)

age = 18

c)

age == 18

23.

What happens when running the following code?

a)

"message" is printed.

b)

"What a cool message!" gets printed to the console.

c)

Python throws a SyntaxError because the string is not surrounded by quotes.

24.

Which of the following defined variables is a string?

a)

cool_variable_1

b)

cool_variable_2

c)

cool_variable_3

d)

cool_variable_4

25.

Which of the following will produce a SyntaxError?

a)
b)
c)
26.

What is the difference between a float and an int?

a)

A float can only be used with whole numbers. An int can be any number with a decimal point.

b)

A float contains text information. An int is any number.

c)

A float represents decimal quantities. An int represents whole numbers.

27.

What is Python syntax for creating a variable and setting it equal to the number 10?

a)

def variable_name = 10

b)

variable_name == 10

c)

new variable_name = 10

d)

variable_name = 10

28.

What is the output of the following code?

a)

210

b)

42

c)

cool_number

29.

What number is saved to exponented_variable in the following expression?

a)

8

b)

16

c)

6

d)

24

30.

What is the value of total_cost that gets printed?

a)

5

b)

15

c)

10

d)

50

31.

What is the value of modulo_variable in the following expression?

a)

56

b)

2

c)

3.5

d)

14.4

32.

What happens when you call report?

a)

Two Strings are printed: "The current time is " and "The mood is "

b)

One String is printed: "The current time is 3pm"

c)

Two Strings are printed: "The current time is 3pm" and "The mood is good"

d)

Three Strings are printed: "The current time is 3pm", "The mood is good", and "End of report"

33.

How do you call a function called setup with no arguments?

a)

setup()

b)

setup(None)

c)

def setup():

d)

setup

34.

How do you call update with a new_value of 20?

a)

def update(20)

b)

update(20)

c)

update

d)

update()

35.

What line of code will call force with a value of 10 for mass and a value of 9.81 for acceleration?

a)

force(mass=10, 9.81)

b)

force(9.81, 10)

c)

force(10, mass=9.81)

d)

force(10, 9.81)

36.

Given the following function, what will produce the output "There is no greater agony than bearing an untold story inside you."?

a)

def quote("an untold story")

b)

quote()

c)

quote("an untold story")

d)

quote(an untold story)

37.

Which of the following variables contains a Boolean value?

a)
b)
c)
d)
38.

Which of the following is a Boolean expression?

a)

This quiz is very hard.

b)

Three is the most elegant number.

c)

The New York Yankees are the classiest baseball team.

d)

My name is Angelo.

39.

Determine the truth value of the following expressions:

a)

A: False

B: True

b)

A: False

B: False

c)

A: True

B: True

d)

A: True

B: False

40.

Determine the truth value of the following expressions:

a)

A: True

B: True

b)

A: False

B: True

c)

A: False

B: False

d)

A: True

B: False

41.

Consider the code. What would this print to the terminal?

a)

Nothing is printed.

b)

Is this printed?

c)

Is this printed?

This might be printed.

d)

This is printed.

This is also printed.

42.

What will the code print when it is executed?

a)

result

b)

A ValueError occurred.

c)

A ZeroDivisionError occurred.

d)

A NameError occurred.

43.

Determine the truth value of the following expressions:

a)

A: True

B: False

b)

A: True

B: True

c)

A: False

B: False

d)

A: False

B: True

44.

Read the following code carefully. What will happen when the code is executed?

a)

"x is equal to zero" will print to the terminal.

b)

There will be a ValueError.

c)

"x is equal to zero" and "x is greater than zero" will print to the terminal.

d)

There will be a SyntaxError.

45.

What is the output of the following python code?

a)

13

b)

10

c)

2

d)

5

46.

What is the output of the following python code?

a)

error

b)

hello

c)

16

d)

16

hello

47.

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)

a)

100

b)

90

c)

80

d)

error

48.

What does the following code do? myAge = int (myAge)

a)

Converts the var (variable) myAge to a string

b)

Converts the var (variable) myAge to a integer

c)

Converts the var (variable) myAge from a integer to a string

d)

Converts the var (variable) myAge to if statement

49.
Python identifies blocks of code by
a)
BEGIN and END keywords
b)
{ and }
c)
aligning up the starts of lines (indentation)
d)
guessing
50.
If you want more than one option for your code, what do you use (after if)?
a)
elif
b)
else
c)
ifif