wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Python KS4 2 mmd

Total questions: 78

Worksheet time: 44mins

Name
Class
Date
1.

A type of error that occurs when a rule of the programming language code is broken?

a)

Syntax error

b)

Logic error

c)

Run-time error

d)

Program error

2.

Which data type would be used in Python to store the value of pi to 2 decimal places?

a)

Integer

b)

Float

c)

Boolean

d)

String

3.

What is this a description of?


A named piece of storage used by a computer program that can change its value

a)

Variable

b)

Constant

c)

Function

d)

Parameter

4.

In what way is a constant different from a variable?

a)

It can not change its value during program execution

b)

It can store more than one value

c)

It can only be used in the global scope

d)

Its name must be written in UPPER CASE

5.

Use the correct order of operations to evaluate this expression ...


6 * 8 / 2 + (15 - 6) + 3 ^ 2

a)

42

b)

32

c)

52

d)

72

6.

The process of giving a value to a variable?

a)

Assignment

b)

Initialisation

c)

Coercion

d)

Declaration

7.

Choose all the recognised control structures in a computer program ...

a)

Sequence

b)

Selection

c)

Iteration

d)

Duplication

8.

Example of ... ?

a)

Selection

b)

Repetition

c)

Sequence

d)

Iteration

9.

Example of ...?

a)

Conditional loop

b)

Unconditional loop

c)

Selection

d)

Sequence

10.

Odd one out ...?

a)
b)
c)
d)
11.

Example of ...?

a)

Sequence

b)

Selection

c)

Repetition

d)

Recursion

12.

Example of ...?

a)

Nested loop

b)

Nested selection

c)

Recursion

d)

Sequence

13.

Example of ...?

a)

Nested selection

b)

Nested loop

c)

Repetition

d)

Iteration

14.

Type of loop to use when the number of repetitions is known before the loop starts?

a)

FOR ... loop

b)

WHILE ... loop

c)

FOR ... EACH ... loop

d)

REPEAT ... UNTIL ...

15.

A special type of loop that never ends?

a)

Infinite loop

b)

Recursive loop

c)

Nested loop

d)

Unconditional loop

16.

Symbols used for entering comments in Python ...?

a)

# This is a Python comment

b)

''' This is a Python comment '''

c)

// This is a Python comment

d)

/* This is a Python comment */

17.

An error in the way a program works where program can run but does not do what it is expected to do is called a ...

a)

Logic error

b)

Syntax error

c)

Runtime error

d)

Catastrophe

18.
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
19.
What will be the output?
name = 'Dave'
print (name)
a)
Dave
b)
'Dave'
c)
name
d)
(name)
20.
What will be the output?
name = 'Dave'
greeting = "Good morning" + name
print (greeting)
a)
Good morning 'Dave'
b)
Good morning Dave
c)
Good morning name
d)
Good morning + Dave
21.
What is the word (command) used to display numbers and text on the screen?
a)
print
b)
input
c)
output
d)
command
22.
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
23.
What symbol is used in python to assign values to a variable?
a)
equals =
b)
plus + 
c)
forward slash /
d)
asterisk *
24.
What is the name of the programming language we are learning?
a)
Scratch
b)
Python
c)
Pie thin
d)
Scribble
25.
What will be the output?
name = 'Dave'
print (name)
a)
Dave
b)
'Dave'
c)
name
d)
(name)
26.
What will be the output?
name = 'Dave'
greeting = "Good morning" + name
print (greeting)
a)
Good morning 'Dave'
b)
Good morning Dave
c)
Good morning name
d)
Good morning + Dave
27.
When you have an error in your code what is the term to summarise finding and fixing that error?
a)
Error checking
b)
Debugging
c)
Syntax finder
d)
Error finder
28.
Which of these would work as a piece of code?
a)
IF answer == "Yes":
b)
if answer == "Yes"
c)
if answer == "Yes":
d)
if answer = "yes":
29.
If you want more than one option for your code, what do you use (after if)?
a)
elif
b)
else
c)
ifif
30.
How do you display text?
a)
input
b)
output
c)
print
d)
variable 
31.
What is python?
a)
a programming language 
b)
DTP software 
c)
Spreadsheet software
d)
Computer 
32.
In Python an ELSE IF statement is represented as what?
a)
elseif
b)
elif
c)
elsif
d)
ifelse
33.
What is the meaning of the following comparison operator?
a > b
a)
Greater than
b)
Less than
c)
Not equal to
d)
Greater than or equal to
34.
What is the meaning of the following comparison operator?
a >= b
a)
Equal to
b)
Not equal to
c)
Greater than or equal to
d)
Less than or equal to
35.
What is the meaning of the following comparison operator?
a != b
a)
Equal to
b)
Greater than
c)
Not equal to
d)
Less than or equal to
36.
IF and ELSE are used when a program needs to make a what?
a)
Repeat
b)
Decision
c)
Change
d)
Output
37.
a)
You can buy some chocloate
b)
You are rich!
c)
Get a job!
d)
You almost have enough
Get a job!
38.
a)
You can buy some chocolate
b)
You are rich
c)
You almost have enough
d)
Get a job!
39.
a)
3, 1, 6, 7, 2, 4, 5
b)
6, 3, 1, 2, 4, 5, 7
c)
3, 6, 1, 2, 4, 5, 7
d)
3, 6, 2, 5, 1, 4, 7
40.
What is syntax?
a)
Syntax is the word used to describe a variable
b)
Syntax is the rules of the programming language
c)
This is used to read information
d)
It is used to output information 
41.
What will the following code do:
print("What is your name?")
a)
Allow you to type in your name
b)
Display the words 'What is your name?' on the screen
c)
Allow you to enter information
d)
Print your name to the screen
42.
The following code is used to create a variable and store a value. Why will it NOT work?
my number = 36
a)
The variable can't store a number
b)
A variable name cannot have any spaces
c)
There variable name can't be called my number
d)
The equals symbol should be at the beginning of the line
43.
What is the output from the following code:
name = "Fred"
print("Hello " + name)
a)
Hello Fred
b)
Hello name
c)
Name error
d)
HelloFred
44.
The following variable contains some data. What is the data type that is being stored.
hobby = "football" 
a)
Integer
b)
Float
c)
String (Text)
d)
Boolean
45.
What will the output be from the following code?
print("Hello world!" * 2)
a)
TypeError
b)
Hello world world!
c)
Hello world!Hello world!
d)
Hello world! * 2
46.
What will the output be from the following code?
print(3+4)
a)
3+4
b)
7
c)
SyntaxError
d)
print(3+4)
47.
What will the output be from the following code?
print("Hello world!")
a)
SyntaxError
b)
Hello world!
c)
"Hello world!"
d)
print(Hello world!)
48.
What will the output be from the following code?
Print("Hello world!")
a)
NameError
b)
Hello world!
c)
"Hello world"
d)
Print(Hello world!)
49.
What will the output be from the following code?
print(Hello world!)
a)
Hello world!
b)
SyntaxError
c)
Hello world
d)
print(Hello world!)
50.

What is a list in python?

a)

A collection of variables

b)

A collection of items assigned to a single variable

c)

A statement that cant be changed

d)

A Christmas list

51.

Which of these codes is correct for creating a list of numbers?

a)

num = ('10','29','37','109')

b)

num = ['10','29','37','109']

c)

num == ('10','29','37','109')

d)

num = ['10 29 37 109']

52.

What is the index number for 'Spain'?

['England','Brazil','Spain','France']

a)

0

b)

1

c)

2

d)

3

53.

How do i remove something from a list?

a)

variable.append()

b)

variable.delete()

c)

variable.remove()

d)

variable=(new variable)

54.

Which code would i use to add an item to a list?

a)

variable.add()

b)

variable.append()

c)

append.variable()

d)

add.variable()

55.

What is used to separate elements in a list?

a)

Bracket

b)

Comma

c)

Full Stop

d)

Space

56.

Why is using lists beneficial?

a)

Shorter Code

b)

More Accurate

c)

It takes less time for the program to run

d)

Its not beneficial

57.

variable.sort() will do what?

a)

Sort the list into alphabetical order

b)

Sort the list into reverse order

c)

Create a new list

d)

Error

58.

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]

59.

Which of the following command is used to open a file “c:\temp.txt” in read-mode only?

a)

infile = open(“c:\temp.txt”, “r”)

b)

infile = open(“c:\\temp.txt”, “r”)

c)

infile = open(file = “c:\temp.txt”, “r+”)

d)

infile = open(file = “c:\\temp.txt”, “r+”)

60.

Which of the following command is used to open a file “c:\temp.txt” in write-mode only?

a)

outfile = open(“c:\temp.txt”, “w”)

b)

outfile = open(“c:\\temp.txt”, “w”)

c)

outfile = open(file = “c:\temp.txt”, “w+”)

d)

outfile = open(file = “c:\\temp.txt”, “w+”)

61.

Which of the following command is used to open a file “c:\temp.txt” in append-mode?

a)

outfile = open(“c:/temp.txt”, “a”)

b)

outfile = open(“c:\temp.txt”, “w+”)

c)

outfile = open(“c:\\temp.txt”, “a”)

d)

outfile = open(“c:\\temp.txt”, “r+”)

62.

Which of the following statements are true regarding the opening modes of a file?

A. When you open a file for reading, if the file does not exist, an error occurs.

B. When you open a file for writing, if the file does not exist, an error occurs.

C. When you open a file for reading, if the file does not exist, the program will open an empty file.

D. When you open a file for writing, if the file does not exist, a new file is created.

E. When you open a file for writing, if the file exists, the existing file is overwritten with the new file.

a)

Only A

b)

A and B

c)

A, D and E

d)

A, B and E

63.

Which of the following commands can be used to read “n” number of characters from a file using the file object <file>?

a)

file.read(n)

b)

n = file.read()

c)

file.readline(n)

d)

file.readlines()

64.

Which of the following commands can be used to read the entire contents of a file as a string using the file object <tmpfile>?

a)

tmpfile.read(n)

b)

tmpfile.read()

c)

tmpfile.readline()

d)

tmpfile.readlines()

65.

Which of the following commands can be used to read the next line in a file using the file object <tmpfile>?

a)

tmpfile.read(n)

b)

tmpfile.read()

c)

tmpfile.readline()

d)

tmpfile.readlines()

66.

What does the <readlines()> method returns?

a)

str

b)

a list of lines

c)

list of single characters

d)

list of integers

67.

Which of the following commands can be used to read the remaining lines in a file using the file object <tmpfile>?

a)

tmpfile.read(n)

b)

tmpfile.read()

c)

tmpfile.readline()

d)

tmpfile.readlines()

68.

What are the two built-in functions to read a line of text from standard input, which is by default the keyboard?

a)

Input

b)

Read

c)

Scanner

69.

What will be the output of the following code snippet?

a)

TechBeamers

Hello viewers!!

b)

Name of the file: myfile.txt

TechBeamers

Hello Viewers!!

c)

TechBeamers Hello viewers!!

d)

Syntax Error

70.

What will be the output of the following code snippet?

a)

TechBeamers

Hello viewers!!

b)

Name of the file: myfile.txt

TechBeamers

Hello Viewers!!

c)

TechBeamers Hello viewers!!

d)

Syntax Error

71.

What will be the output of the following code snippet?

Assuming that input given by user is :Tech Beamers

a)

Tech Beamers

b)

Tech

c)

Tech

Beamers

d)

Syntax Error

72.

What will be the output of the following code snippet?

a)

Runtime Error

b)

Hello World how are you today

c)

[‘Hello’, ‘World’, ‘how’, ‘are’, ‘you’, ‘today’]

d)

Hello

73.

What is the correct syntax of open() function?

a)

file_name = open(file_name [, access_mode][, buffering])

b)

file_object = open(file_name [, access_mode][, buffering])

c)

file object = open(file_name)

d)

None of the above

74.

What will be the output of the following code snippet?

a)

Runtime Error

b)

True

c)

False

d)

Hello world

75.

What will be the output of the following code snippet?

a)

Runtime Error

b)

[‘This is 1st line\n’, ‘ This is 2nd line\n’, ‘This is 3rd line’]

c)

[‘ This is 2nd line\n’, ‘This is 3rd line’]

d)

[ ]

76.

Which of the following statements is correct regarding the seek() method?

a)

sets the file position to the end of file

b)

position of file pointer remains unchanged

c)

sets the file's current position at the offset

d)

the file pointer is set to the start of the file

77.

What will be the output of the following code snippet?

a)

red

yellow

blue

b)

[‘red\n’, ‘yellow\n’, ‘blue\n’]

c)

Error: I/O operation on closed file

d)

Compilation error

78.

What is the use of tell() method in python?

a)

tells you the current position within the file

b)

tells you the end position within the file

c)

tells you the file is opened or not

d)

none of the mentioned