wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Python Review

Total questions: 54

Worksheet time: 22mins

Name
Class
Date
1.

How do you write a print statment to print the following string: 'Hello World'?

(a)  

2.

How do you write a print statement with a variable called myName?

(a)  

3.

How would you write an input statement that sets a variable as the users input

a)

variable == input("Enter a value: ")

b)

variable = input(Enter a value: )

c)

input = ("Enter a value: ")

d)

variable = input("Enter a value: ")

4.

Will this add the number

a)

Yes

b)

No

5.

Select the python math operators that work

a)

x

b)

+

c)

÷

d)

-

e)

/

6.

what types of things can variable be set to?

a)

Boolean

b)

String

c)

Number

d)

All of the above

7.

This will give me an error

a)

True

b)

False

8.
What is a variable?
a)
A box(memory location) where you store values
b)
a type of graphics
c)
Data type
d)
a type of memory
9.

What will be the output?

name = 'Dave'

greeting = "Good morning" + name

print (greeting)

a)

Good morning 'Dave'

b)

Good morningDave

c)

Good morning name

d)

Good morning Dave

10.

what are the conditions in python if statements?

a)

else

b)

else/if

c)

elif

d)

if

e)

elf

11.

Which symbols surround a list?

a)

[]

b)

{}

c)

()

d)

||

12.

Which function changes a string to a float?

a)

float()

b)

num()

c)

print()

d)

change()

13.

A list is changeable and unordered

a)

True

b)

False

14.

List items have an index number. In the following list, which item has the index number of 3?

["John", "Harry", "Jesse", "John", "Harry", "Harry"]

a)

"John"

b)

"Harry"

c)

"Jesse"

15.

The list needs one more name added to the end - "Felipe". Which piece of code below would do this?

nameList = ["John", "Harry", "Jesse", "John", "Harry", "Harry"]

a)

nameList.append(Felipe)

b)

append(nameList,"Felipe")

c)

nameList.append["Felipe",7]

d)

nameList.append("Felipe")

16.

Which code should you use to import a function named abc from a Python module named xyz?

a)

import abc

b)

from xyz import abc

c)

import abc from xyz

d)

import mod xyz fn abc

17.

You are comparing two numerical values in the following operation:

In [1]: 9 ___ 9

Out[1]: True

Which operator correctly completes the operation?

a)

=>

b)

=!

c)

>=

18.

Which statement about local variables is true?

a)

A local variable can be read from the global scope.

b)

You can use the same variable name in multiple functions.

c)

A local variable in one function can be read from another function.

d)

A function can update a global variable in a local scope by using the same name for a local variable and assigning a new value.

19.

Complete the sentence to be true for code running in a Python environment.

A local scope is created...

a)

when a function is created

b)

when a function is called

c)

when a function returns to its caller

d)

when a function is destroyed

20.

When a function calls a subfunction, which variables are maintained in memory? (Choose all that apply.)

a)

The global variables

b)

The function variables

c)

The subfunction variables

21.

Which clause should you use for code that you want to execute regardless of whether an exception is raised?

a)

else

b)

elseif

c)

except

d)

finally

22.

True or False: When handling exceptions, Python code can include an else clause or a finally clause, but not both.

a)

True

b)

False

23.

In what format does a dictionary store information?

a)

(key, value)

b)

[key:value]

c)

{key, value}

d)

{key:value}

24.

True or False: In Python, using the `raise` statement allows the programmer to define and raise their own exception.

a)

True

b)

False

25.

Which two statements about key:value pairs are correct? (Choose two.)

a)

Keys are unique

b)

Values are unique

c)

A value can be associated with multiple keys

d)

Keys within a dictionary must be of the same type

26.

Which of the following statements about tuples is true?

a)

A tuple can contain list elements.

b)

A tuple cannot contain another tuple.

c)

After you define a tuple, you can add elements to it.

d)

You define the elements of a tuple within square brackets.

27.

In which two ways is a tuple like a list? (Choose two.)

a)

Lists and tuples are data structures that can store a sequence of elements.

b)

Lists and tuples are immutable data structures.

c)

Lists and tuples can contain int, float, list, and string elements.

d)

You can reorder the elements of lists and tuples.

28.

Which function can you use to list the contents of the current working directory?

a)

os.chdir()

b)

os.getcwd()

c)

os.listdir()

d)

os.rmdir()

29.

What type of loop should you use to repeat a code process as long as a condition resolves as `True`?

a)

compound

b)

for

c)

nested

d)

while

30.

Which function can you use to test whether an absolute or relative path to a folder is valid?

a)

os.path.commonpath(paths)

b)

os.path.exists(path)

c)

os.path.normpath(path)

d)

os.path.realpath(path)

31.

True or False: An infinite loop is a loop that runs until the value returned by the loop condition is False.

a)

True

b)

False

32.
What is python named after
a)
The snake
b)
Television show called Monty Python
33.
What will the output be from the following code?
print("Hello world!\nHello world!")
a)
Hello world! Hello world!
b)
Hello world!
Hello world!
c)
SyntaxError
d)
Hello world!
34.
If you want more than one option for your code, what do you use (after if)?
a)
elif
b)
else
c)
ifif
35.

people = ["John", "Rob", "Bob"]

print (people[1])

what would this result be?

a)
John
b)
Rob
c)
Bob
36.

people = ["John", "Rob", "Bob"]

print (people[4])

what would this result be?

a)
John
b)
Rob
c)
Bob
d)
Error
37.
What symbol do you use to make a comment in Python?
a)
@
b)
¬
c)
;
d)
#
38.
In python the ' INTEGER data type' can be defined as...?
a)
holds alphanumeric data as text
b)
holds whole numbers
c)
holds numbers with a decimal point
d)
holds either ‘true’ or ‘false’
39.
In python the ' FLOAT data type' can be defined as...?
a)
holds alphanumerical data
b)

holds whole numbers

c)

holds a decimal point in a number

d)
hold either true or false
40.
what is the code for a STRING in python?
a)
str
b)
stri
c)
stg
41.

Which operator can be used to check if two values are equal to each other?

a)

==

b)

><

c)

<>

d)

=

42.

How do you create a function called myFunction in Python?

(a)  

43.

Python uses indentation to block code into chunks

a)

True

b)

False

44.

What output will the console show, if 15 and 30 are entered by the user?

a)

Syntax error

b)

The sum of the two numbers - 45

c)

The concatenation of the two numbers - 1530

d)

Complier error

45.
surrounds multi-line comments
a)
"""
b)
**
c)
#
d)
%
46.

Given the nested if-else below, what will be the value x when the code is executed successfully.

a)

0

b)

4

c)

2

d)

3

47.

What will:

answer = input("Give me a number")

print(answer * 5)

output?

a)

An error message

b)

The value of answer multiplied by 5

c)

answer * 5

d)

The value of answer repeated 5 times

48.

What can a variable not start with?

a)

A special character

b)

A capital letter

c)

A number

d)

A lower case letter

49.

What does print("hello) display?

a)

hello

b)

gives you an error

c)

"hello"

d)

"hello

50.

'my name' is a valid variable?

a)

No

b)

Yes

51.

Suppose you write a function. How many times can you call the function in your code?

a)

Once

b)

Not more than the number of commands the function holds

c)

It depends on the function

d)

As many times as you want

52.

Which of the statements below is true about indentation in Python?

a)

Indentation only matters in for loops. Then, everything must be indented one level.

b)

Indentation never matters in Python. You can align your code any way you like, but indentation makes your code easier to read.

c)

Indentation always matters in Python. Every statement must be aligned correctly.

d)

Indentation only matters in functions. Then, everything must be indented one level.

53.

Which of the following functions is declared correctly?

a)
b)
c)
d)
54.

Which program below includes no errors?

a)
b)
c)
d)