WorksheetsPython Test 2
Total questions: 80
Worksheet time: 1hrs 12mins
What extension must you add to the end of a file when saving?
.xlsx
.pptx
.docx
.py
What does the term 'debug' mean?
Identify errors and fix them.
Making a calculation
A set of instructions
Looking at code
name = 'Dave'
print (name)
What is a input?
A function that allows us to ask the user to enter some data.
To plug in something.
Data displayed on a screen.
A function
What is a output?
A piece of data that is shown on the screen.
Data that the user enters
An output
A orange
Why would you use a loop?
To repeat a piece of code
To create a loop
To input data
Which of the following is used in Python to calculate ten squared?
s = "programming rocks"
print(len(s))
cheer = "Go Eagles!"
print cheer[5:8]
ss = "Hola, friend"
print(ss.upper())
s = "python rocks"
print(s[-3])
s = "python rocks"
print(s[7:11] * 3)
What is the output?
a = 10
b = "python"
c = a
print(b, c, a)
(a)
What is the value of x?
a = 3
b = 2
c = 1
x = (a > b) and (c > b)
True
False
x is undefined
What is the value of f?
a = 5
b = 4
c = 1
f = a+b > b+3 or b*2 < a+1
True
False
f is undefined
How many times does the print statement execute?
i = 1
while i < 5:
print(i)
i = i + 2
0
1
2
3
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")
Apple
Orange
Banana
Melon
What is the output?
a = 9
b = 3
c = 5
if a > b + c or b > c:
print("Pass")
else:
print("Fail")
Pass
Fail
What is the output?
thislist = ["A", "B", "N", "D"]
thislist.remove("B")
thislist.append("X")
thislist[2] = "V"
print(thislist)
["A", "B", "N", "D"]
["A", "N", "V","X"]
["A", "V","N", "X"]
["A", "V","N", "D" ,"X"]
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)
4 8
tan khaki gray
4 8
4 8
4 8
tan khaki gray
tan khaki gray
tan khaki gray
tan 4
tan 8
khaki 4
khaki 8
gray 4
gray 8
tan 4
khaki 4
gray 4
tan 8
khaki 8
gray 8
a = "points"
b = 4
c = "more"
print(b, c, a)
(a)
What is the output?
for i in range(3):
print(i + 2)
0
1
2
0
2
4
2
3
4
Result of the program above is
('1', '2', '3', '4', '5')
(1, 2, 3, 4, 5)
12345
"12345"
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]
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"]
nameList.append(Felipe)
append(nameList,"Felipe")
nameList.append["Felipe",7]
nameList.append("Felipe")
To insert an the string "strawberries" in the first position of a list we use
fruit.append("strawberries, 1")
fruit.insert("strawberries",0)
fruit.insert(1, "strawberries")
fruit.insert(0, "strawberries")
Is this the correct code for a list?
register = {"Sam", "Pheobe", Georgia", Richard"}
Yes
No
A while loop can be used in which of the following situations?
Repeat a set of statements till a condition remains True.
Repeat a set of statements a finite or an infinite number of times.
Iterate through a string, list, and tuple.
All of the above
What is a variable?
a type of graphics
A box(memory location) where you store values
Data type
a type of memory
A syntax error means your code has a 'grammar' mistake or you used symbols/operations incorrectly
True
False
What will be the output?
name = "Dave"
print (name)
(name)
Dave
name
Nothing
What is a piece of code that can take inputs to perform a certain task?
a function
arguments
parameters
What term is used to describe data passed into/out of a program?
Variable
Loop
Constant
Parameter
Which of the following keywords marks the begining of the function block?
Func
define
def
function
Which of the following items are present in the function header?
Function name only
Both function name and parameter list
parameter list only
Return value
Which of the following items are present in the function header?
Function name only
Both function name and parameter list
parameter list only
Return value
What is a parameter in a function?
input value to a function for the function’s execution
a variable used to send information to a function
the name of the function
the name of the main program calling the function
Which of these is a list?
fruit = ["apples", "oranges", "bananas"]
fruit = "apples", "oranges", "bananas"
fruit = {"apples", "oranges", "bananas"}
fruit = ("apples", "oranges", "bananas")
Each item in a list has an "address" or index. The first index in a Python list is what?
1
0
a
A
What output will this code produce?
['France', 'Wales', 'England']
France
France Wales England
France
France, Wales, England
Wales
['France', 'Wales', 'England']
Wales
In programming, lists are often known as...
Arrays
Elements
Indexes
Data
What is an algorithm?
A set of steps for performing a task, like a recipe.
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.
A value passed to a function.
A rhythm designed for people named "Al."
Statements or instructions written by a programmer in a language that computers can understand defines...
algorithm
code
software
range
Comments are
statements only the computer can understand.
programming notes or reminders that the computer ignores.
not appreciated.
statements that allow the computer to test a value and perform different actions depending on the outcome of that test.
An expression is
A set of steps for performing a task, like a recipe.
An ordered list of values or objects.
To combine two strings of text into a single string.
Any valid set of values, variables, operators, and functions that produces a value or result.
A programming statement that allows a block of code to be repeated for a given range of values defines
function
while loop
for loops
applications
A named, reusable set of programming statements to perform a specific task defines
applications
algorithms
modules
functions
Import means
A named, reusable set of programming statements to perform a specific task.
A programming statement that allows a block of code to be repeated for a given range of values.
To bring reusable code or data into a program from another program or module.
Any data or information entered into a computer.
A set of instructions that is repeated until a condition is reached is
a loop
code
a function
an expression
A file or set of files with related variables, functions, and classes that can be reused in other programs defines
loop
module
comments
expression
An ordered set of values between a known start and end value is the
radius
loop
range
expression
The spelling and grammar rules of a programming language is called
GSP
syntax
code
comments
Variables are
any valid set of values, variables, operators and functions that produce a value or result.
unpredictable sequences of numbers evenly distributed over a certain range.
a sequence of characters, which can include letters, numbers, symbols, punctuation and spacing.
named values that can change.
A string is
A named value that can change.
A sequence of characters, which can include letters, numbers, symbols, punctuation and spacing.
A file or set of files with related variables, functions, and classes that can be reused in other programs.
A named, reusable set of programming statements to perform a specific task.
Rewrite this line of code correctly!
(a)
Which of these is true?
A syntax error will stop a program running
A logic error will stop a program running
A syntax error will let the program run but may have unexpected outcomes
The program will always show an error message for a logic error
What does \n do?
Adds a quotation
Creates a number
Adds a new line
Adds a fullstop
How do you ask an input from a user?
name = int("what is your name")
name = input(what is your name?)
input = name("what is your name?")
name = input("what is your name?")
Pieces of code that only run "under certain conditions":
conditional statements
control flow statments
syntax
variables
Which symbol means "not equal to"?
==
<=
>=
!=
If you want to test more than one condition (chained condition), what do you use after if statement?
elif
else
ifif
else if
Which character must be at the end of the line for if?
:
;
.
{
1. Which of the functions is called when z = 12?
sayHi()
sayHello()
sayGoodbye()
Which of the following is true about if-elif-else statements?
After using if, an elif can be added as an additional test
The bodies of multiple elif’s can run
You can use an elif without an if
Code in an else body runs if all the tests before it were True
Which is correct?
if num1==42:
print("You have discovered the meaning of life!")
if num1==42...
print("You have discovered the meaning of life!")
if num1==42:
print "You have discovered the meaning of life!"
if num1==42:
print( You have discovered the meaning of life!)
When writing an if/else statement, you
always indent the line after the condition
never indent the line after the condition
capitalize every word
put a colon at the beginning and the end
In Python, the command "while" will create a:
loop
variable
function
a chocolate cake
In a loop, as long as the user enters an answer that is "true,"
the command repeats itself
the program ends
the programs starts over
the user gains 10 points
56.867
String
Integer
Float
Decimal
" "
String
Integer
Float
Number
strings
quotes
syntax
input
