Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Python Test 2

Total questions: 80

Worksheet time: 1hrs 12mins

Name
Class
Date
1.

What extension must you add to the end of a file when saving?

a)

.xlsx

b)

.pptx

c)

.docx

d)

.py

2.

What does the term 'debug' mean?

a)

Identify errors and fix them.

b)

Making a calculation

c)

A set of instructions

d)

Looking at code

3.
What does the print function do in python?
a)
It's a variable.
b)
It can input data.
c)
It displays something like a string or integer
d)
It loops the code.
4.
What is the word (command) used to display numbers and text on the screen?
a)
print
b)
input
c)
output
d)
command
5.
What symbol is used in python to assign values to a variable?
a)
equals =
b)
plus + 
c)
forward slash /
d)
asterisk *
6.
What will be the output?
name = 'Dave'
print (name)
a)
Dave
b)
'Dave'
c)
name
d)
(name)
7.
Python is an example of a....
a)
Text-based programming language
b)
Object orientated programming language
c)
language written in java script
d)
Visual-based programming language
8.

What is a input?

a)

A function that allows us to ask the user to enter some data.

b)

To plug in something.

c)

Data displayed on a screen.

d)

A function

9.

What is a output?

a)

A piece of data that is shown on the screen.

b)

Data that the user enters

c)

An output

d)

A orange

10.

Why would you use a loop?

a)

To repeat a piece of code

b)

To create a loop

c)

To input data

11.
102 = 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
12.
What is printed by the following statements?
s = "programming rocks"
print(len(s))
a)
12
b)
17
c)
16
d)
nothing - there is an error
13.
What is printed by the following statements?
cheer = "Go Eagles!"
print cheer[5:8]
a)
gle
b)
agle
c)
gles
d)
agles
14.
What is printed by the following statements?
ss = "Hola, friend"
print(ss.upper())
a)
hola, friend
b)
Hola, Friend
c)
HOLA, FRIEND
d)
Hola, friend
15.
What is printed by the following statements?
s = "python rocks"
print(s[-3])
a)
c
b)
k
c)
s
d)
Error
16.
What is printed by the following statements:
s = "python rocks"
print(s[7:11] * 3)
a)
rockrockrock
b)
rock rock rock rock
c)
pythonrockrockrock
d)
pythonrocksrocksrocks
17.
Converts a number to a string
a)
str()
b)
int()
c)
parseInt()
d)
convert
18.

What is the output?

a = 10

b = "python"

c = a

print(b, c, a)

(a)  

19.

What is the value of x?

a = 3

b = 2

c = 1

x = (a > b) and (c > b)

a)

True

b)

False

c)

x is undefined

20.

What is the value of f?

a = 5

b = 4

c = 1

f = a+b > b+3 or b*2 < a+1

a)

True

b)

False

c)

f is undefined

21.

How many times does the print statement execute?

i = 1

while i < 5:

print(i)

i = i + 2

a)

0

b)

1

c)

2

d)

3

22.

What is the output?

a = 5

b = 2

c = 1

if a > b + c:

if a != b * c:

print("Apple")

else:

print("Orange")

else:

if b + c < a + b:

print("Banana")

else:

print("Melon")

a)

Apple

b)

Orange

c)

Banana

d)

Melon

23.

What is the output?

a = 9

b = 3

c = 5

if a > b + c or b > c:

print("Pass")

else:

print("Fail")

a)

Pass

b)

Fail

24.

What is the output?

thislist = ["A", "B", "N", "D"]

thislist.remove("B")

thislist.append("X")

thislist[2] = "V"

print(thislist)

a)

["A", "B", "N", "D"]

b)

["A", "N", "V","X"]

c)

["A", "V","N", "X"]

d)

["A", "V","N", "D" ,"X"]

25.

What is the result of running the following code?

colors = ['tan', 'khaki', 'gray']

sizes = [4, 8]

for i in colors:

for j in sizes:

print(i, j)

a)

4 8

tan khaki gray

b)

4 8

4 8

4 8

tan khaki gray

tan khaki gray

tan khaki gray

c)

tan 4

tan 8

khaki 4

khaki 8

gray 4

gray 8

d)

tan 4

khaki 4

gray 4

tan 8

khaki 8

gray 8

26.

a = "points"

b = 4

c = "more"

print(b, c, a)

(a)  

27.

What is the output?

for i in range(3):

print(i + 2)

a)

0

1

2

b)

0

2

4

c)

2

3

4

28.

Result of the program above is

a)

('1', '2', '3', '4', '5')

b)

(1, 2, 3, 4, 5)

c)

12345

d)

"12345"

29.

Which of these is the correct code for creating a list of names?

a)

nameList = John, Harry, Jesse, John, Harry, Harry

b)

nameList = ("John", "Harry", "Jesse", "John", "Harry", "Harry")

c)

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

d)

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

30.

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")

31.
What is the position of the name "Robert" in the following list:
a)
0
b)
1
c)
2
d)
3
32.
What output will this code produce?
a)
blue
b)
green
c)
red
d)
error
33.

To insert an the string "strawberries" in the first position of a list we use

a)

fruit.append("strawberries, 1")

b)

fruit.insert("strawberries",0)

c)

fruit.insert(1, "strawberries")

d)

fruit.insert(0, "strawberries")

34.

Is this the correct code for a list?

register = {"Sam", "Pheobe", Georgia", Richard"}

a)

Yes

b)

No

35.

A while loop can be used in which of the following situations?

a)

Repeat a set of statements till a condition remains True.

b)

Repeat a set of statements a finite or an infinite number of times.

c)

Iterate through a string, list, and tuple.

d)

All of the above

36.

What is a variable?

a)

a type of graphics

b)

A box(memory location) where you store values

c)

Data type

d)

a type of memory

37.

A syntax error means your code has a 'grammar' mistake or you used symbols/operations incorrectly

a)

True

b)

False

38.

What will be the output?

name = "Dave"

print (name)

a)

(name)

b)

Dave

c)

name

d)

Nothing

39.

What is a piece of code that can take inputs to perform a certain task?

a)

a function

b)

arguments

c)

parameters

40.

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

a)

Variable

b)

Loop

c)

Constant

d)

Parameter

41.

Which of the following keywords marks the begining of the function block?

a)

Func

b)

define

c)

def

d)

function

42.

Which of the following items are present in the function header?

a)

Function name only

b)

Both function name and parameter list

c)

parameter list only

d)

Return value

43.
What will print?
a)
nothing
b)
5
c)
6
d)
an error message
44.

Which of the following items are present in the function header?

a)

Function name only

b)

Both function name and parameter list

c)

parameter list only

d)

Return value

45.

What is a parameter in a function?

a)

input value to a function for the function’s execution

b)

a variable used to send information to a function

c)

the name of the function

d)

the name of the main program calling the function

46.

Which of these is a list?

a)

fruit = ["apples", "oranges", "bananas"]

b)

fruit = "apples", "oranges", "bananas"

c)

fruit = {"apples", "oranges", "bananas"}

d)

fruit = ("apples", "oranges", "bananas")

47.

Each item in a list has an "address" or index. The first index in a Python list is what?

a)

1

b)

0

c)

a

d)

A

48.

What output will this code produce?

a)

['France', 'Wales', 'England']

France

b)

France Wales England

France

c)

France, Wales, England

Wales

d)

['France', 'Wales', 'England']

Wales

49.

In programming, lists are often known as...

a)

Arrays

b)

Elements

c)

Indexes

d)

Data

50.

What is an algorithm?

a)

A set of steps for performing a task, like a recipe.

b)

To add something to the end; for example, adding letters onto the end of a string or adding elements to the end of a list or array.

c)

A value passed to a function.

d)

A rhythm designed for people named "Al."

51.

Statements or instructions written by a programmer in a language that computers can understand defines...

a)

algorithm

b)

code

c)

software

d)

range

52.

Comments are

a)

statements only the computer can understand.

b)

programming notes or reminders that the computer ignores.

c)

not appreciated.

d)

statements that allow the computer to test a value and perform different actions depending on the outcome of that test.

53.

An expression is

a)

A set of steps for performing a task, like a recipe.

b)

An ordered list of values or objects.

c)

To combine two strings of text into a single string.

d)

Any valid set of values, variables, operators, and functions that produces a value or result.

54.

A programming statement that allows a block of code to be repeated for a given range of values defines

a)

function

b)

while loop

c)

for loops

d)

applications

55.

A named, reusable set of programming statements to perform a specific task defines

a)

applications

b)

algorithms

c)

modules

d)

functions

56.

Import means

a)

A named, reusable set of programming statements to perform a specific task.

b)

A programming statement that allows a block of code to be repeated for a given range of values.

c)

To bring reusable code or data into a program from another program or module.

d)

Any data or information entered into a computer.

57.

A set of instructions that is repeated until a condition is reached is

a)

a loop

b)

code

c)

a function

d)

an expression

58.

A file or set of files with related variables, functions, and classes that can be reused in other programs defines

a)

loop

b)

module

c)

comments

d)

expression

59.

An ordered set of values between a known start and end value is the

a)

radius

b)

loop

c)

range

d)

expression

60.

The spelling and grammar rules of a programming language is called

a)

GSP

b)

syntax

c)

code

d)

comments

61.

Variables are

a)

any valid set of values, variables, operators and functions that produce a value or result.

b)

unpredictable sequences of numbers evenly distributed over a certain range.

c)

a sequence of characters, which can include letters, numbers, symbols, punctuation and spacing.

d)

named values that can change.

62.

A string is

a)

A named value that can change.

b)

A sequence of characters, which can include letters, numbers, symbols, punctuation and spacing.

c)

A file or set of files with related variables, functions, and classes that can be reused in other programs.

d)

A named, reusable set of programming statements to perform a specific task.

63.

Rewrite this line of code correctly!

(a)  

64.
a data type than can have one of two values: True or False
a)
boolean
b)
variable
c)
modulo
d)
interpreter
65.

Which of these is true?

a)

A syntax error will stop a program running

b)

A logic error will stop a program running

c)

A syntax error will let the program run but may have unexpected outcomes

d)

The program will always show an error message for a logic error

66.

What does \n do?

a)

Adds a quotation

b)

Creates a number

c)

Adds a new line

d)

Adds a fullstop

67.

How do you ask an input from a user?

a)

name = int("what is your name")

b)

name = input(what is your name?)

c)

input = name("what is your name?")

d)

name = input("what is your name?")

68.

Pieces of code that only run "under certain conditions":

a)

conditional statements

b)

control flow statments

c)

syntax

d)

variables

69.

Which symbol means "not equal to"?

a)

==

b)

<=

c)

>=

d)

!=

70.

If you want to test more than one condition (chained condition), what do you use after if statement?

a)

elif

b)

else

c)

ifif

d)

else if

71.

Which character must be at the end of the line for if?

a)

:

b)

;

c)

.

d)

{

72.

1. Which of the functions is called when z = 12?

a)

sayHi()

b)

sayHello()

c)

sayGoodbye()

73.

Which of the following is true about if-elif-else statements?

a)

After using if, an elif can be added as an additional test

b)

The bodies of multiple elif’s can run

c)

You can use an elif without an if

d)

Code in an else body runs if all the tests before it were True

74.

Which is correct?

a)

if num1==42:

print("You have discovered the meaning of life!")

b)

if num1==42...

print("You have discovered the meaning of life!")

c)

if num1==42:

print "You have discovered the meaning of life!"

d)

if num1==42:

print( You have discovered the meaning of life!)

75.

When writing an if/else statement, you

a)

always indent the line after the condition

b)

never indent the line after the condition

c)

capitalize every word

d)

put a colon at the beginning and the end

76.

In Python, the command "while" will create a:

a)

loop

b)

variable

c)

function

d)

a chocolate cake

77.

In a loop, as long as the user enters an answer that is "true,"

a)

the command repeats itself

b)

the program ends

c)

the programs starts over

d)

the user gains 10 points

78.

56.867

a)

String

b)

Integer

c)

Float

d)

Decimal

79.

" "

a)

String

b)

Integer

c)

Float

d)

Number

80.
a)

strings

b)

quotes

c)

syntax

d)

input