Font size
WorksheetsPython KS4 2 mmd
Total questions: 78
Worksheet time: 44mins
A type of error that occurs when a rule of the programming language code is broken?
Syntax error
Logic error
Run-time error
Program error
Which data type would be used in Python to store the value of pi to 2 decimal places?
Integer
Float
Boolean
String
What is this a description of?
A named piece of storage used by a computer program that can change its value
Variable
Constant
Function
Parameter
In what way is a constant different from a variable?
It can not change its value during program execution
It can store more than one value
It can only be used in the global scope
Its name must be written in UPPER CASE
Use the correct order of operations to evaluate this expression ...
6 * 8 / 2 + (15 - 6) + 3 ^ 2
42
32
52
72
The process of giving a value to a variable?
Assignment
Initialisation
Coercion
Declaration
Choose all the recognised control structures in a computer program ...
Sequence
Selection
Iteration
Duplication
Example of ... ?
Selection
Repetition
Sequence
Iteration
Example of ...?
Conditional loop
Unconditional loop
Selection
Sequence
Odd one out ...?
Example of ...?
Sequence
Selection
Repetition
Recursion
Example of ...?
Nested loop
Nested selection
Recursion
Sequence
Example of ...?
Nested selection
Nested loop
Repetition
Iteration
Type of loop to use when the number of repetitions is known before the loop starts?
FOR ... loop
WHILE ... loop
FOR ... EACH ... loop
REPEAT ... UNTIL ...
A special type of loop that never ends?
Infinite loop
Recursive loop
Nested loop
Unconditional loop
Symbols used for entering comments in Python ...?
# This is a Python comment
''' This is a Python comment '''
// This is a Python comment
/* This is a Python comment */
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 ...
Logic error
Syntax error
Runtime error
Catastrophe
name = 'Dave'
print (name)
name = 'Dave'
greeting = "Good morning" + name
print (greeting)
name = 'Dave'
print (name)
name = 'Dave'
greeting = "Good morning" + name
print (greeting)
a > b
a >= b
a != b
Get a job!
print("What is your name?")
my number = 36
name = "Fred"
print("Hello " + name)
hobby = "football"
print("Hello world!" * 2)
print(3+4)
print("Hello world!")
Print("Hello world!")
print(Hello world!)
What is a list in python?
A collection of variables
A collection of items assigned to a single variable
A statement that cant be changed
A Christmas list
Which of these codes is correct for creating a list of numbers?
num = ('10','29','37','109')
num = ['10','29','37','109']
num == ('10','29','37','109')
num = ['10 29 37 109']
What is the index number for 'Spain'?
['England','Brazil','Spain','France']
0
1
2
3
How do i remove something from a list?
variable.append()
variable.delete()
variable.remove()
variable=(new variable)
Which code would i use to add an item to a list?
variable.add()
variable.append()
append.variable()
add.variable()
What is used to separate elements in a list?
Bracket
Comma
Full Stop
Space
Why is using lists beneficial?
Shorter Code
More Accurate
It takes less time for the program to run
Its not beneficial
variable.sort() will do what?
Sort the list into alphabetical order
Sort the list into reverse order
Create a new list
Error
Which of these is the correct code for creating a list of names?
nameList = John, Harry, Jesse, John, Harry, Harry
nameList = ("John", "Harry", "Jesse", "John", "Harry", "Harry")
nameList = ["John", "Harry", "Jesse", "John", "Harry", "Harry"]
nameList = [John, Harry, Jesse, John, Harry, Harry]
Which of the following command is used to open a file “c:\temp.txt” in read-mode only?
infile = open(“c:\temp.txt”, “r”)
infile = open(“c:\\temp.txt”, “r”)
infile = open(file = “c:\temp.txt”, “r+”)
infile = open(file = “c:\\temp.txt”, “r+”)
Which of the following command is used to open a file “c:\temp.txt” in write-mode only?
outfile = open(“c:\temp.txt”, “w”)
outfile = open(“c:\\temp.txt”, “w”)
outfile = open(file = “c:\temp.txt”, “w+”)
outfile = open(file = “c:\\temp.txt”, “w+”)
Which of the following command is used to open a file “c:\temp.txt” in append-mode?
outfile = open(“c:/temp.txt”, “a”)
outfile = open(“c:\temp.txt”, “w+”)
outfile = open(“c:\\temp.txt”, “a”)
outfile = open(“c:\\temp.txt”, “r+”)
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.
Only A
A and B
A, D and E
A, B and E
Which of the following commands can be used to read “n” number of characters from a file using the file object <file>?
file.read(n)
n = file.read()
file.readline(n)
file.readlines()
Which of the following commands can be used to read the entire contents of a file as a string using the file object <tmpfile>?
tmpfile.read(n)
tmpfile.read()
tmpfile.readline()
tmpfile.readlines()
Which of the following commands can be used to read the next line in a file using the file object <tmpfile>?
tmpfile.read(n)
tmpfile.read()
tmpfile.readline()
tmpfile.readlines()
What does the <readlines()> method returns?
str
a list of lines
list of single characters
list of integers
Which of the following commands can be used to read the remaining lines in a file using the file object <tmpfile>?
tmpfile.read(n)
tmpfile.read()
tmpfile.readline()
tmpfile.readlines()
What are the two built-in functions to read a line of text from standard input, which is by default the keyboard?
Input
Read
Scanner
What will be the output of the following code snippet?
TechBeamers
Hello viewers!!
Name of the file: myfile.txt
TechBeamers
Hello Viewers!!
TechBeamers Hello viewers!!
Syntax Error
What will be the output of the following code snippet?
TechBeamers
Hello viewers!!
Name of the file: myfile.txt
TechBeamers
Hello Viewers!!
TechBeamers Hello viewers!!
Syntax Error
What will be the output of the following code snippet?
Assuming that input given by user is :Tech Beamers
Tech Beamers
Tech
Tech
Beamers
Syntax Error
What will be the output of the following code snippet?
Runtime Error
Hello World how are you today
[‘Hello’, ‘World’, ‘how’, ‘are’, ‘you’, ‘today’]
Hello
What is the correct syntax of open() function?
file_name = open(file_name [, access_mode][, buffering])
file_object = open(file_name [, access_mode][, buffering])
file object = open(file_name)
None of the above
What will be the output of the following code snippet?
Runtime Error
True
False
Hello world
What will be the output of the following code snippet?
Runtime Error
[‘This is 1st line\n’, ‘ This is 2nd line\n’, ‘This is 3rd line’]
[‘ This is 2nd line\n’, ‘This is 3rd line’]
[ ]
Which of the following statements is correct regarding the seek() method?
sets the file position to the end of file
position of file pointer remains unchanged
sets the file's current position at the offset
the file pointer is set to the start of the file
What will be the output of the following code snippet?
red
yellow
blue
[‘red\n’, ‘yellow\n’, ‘blue\n’]
Error: I/O operation on closed file
Compilation error
What is the use of tell() method in python?
tells you the current position within the file
tells you the end position within the file
tells you the file is opened or not
none of the mentioned
