WorksheetsPython Final Test Review
Total questions: 92
Worksheet time: 51mins
print(Hello world!)
What will the output be from the following code? print("Hello" + str(3) + "world!")
Hello3World!
Hello Hello Hello world world! world!
Which function/command will change the current working directory
os.getcwd
os.changedir
os.mkdir
os.chdir
What code will execute a new sub-directory called "new_student"
os.mkdir('new_student')
import os
os.mkdir('new_student')
print(os.listdir())
import os
os.chdir('new_student')
print(os.listdir())
os.chdir('new_student')
Which of the following is used in Python to calculate ten squared?
What will be the output? name = 'Isiah' print (name)
Isiah
'Isiah'
print("Hello world!" * 2)
There are 40 students in a classroom. We would like to get all students whose name starts with "A". Which looping is suitable?
For loop
While loop
Python is _____ sensitive which means you must use the same indentation every time.
space
colour
code
word
people = ["Larry", "Rob", "Kacy", "Joe"]
print (people[4])
what would this result be?
Larry
Joe
Kacy
people = ["Tony", "Yasmin", "Henry", "Sam"]
print (people[-1])
what would this result be?
Tony
Yasmin
Henry
Sam
What will the output be for the code shown here?
for count in range (3,0,-1)
print(count)
3,2,1,0
0,1,2,3
3,2,1
1,2,3
What will the output be from the following code? print(3*4+6)
17
18
What does the following code do? myAge = int (myAge)
Converts the var (variable) myAge to a string
Converts the var (variable) myAge to a integer
Converts the var (variable) myAge from a integer to a string
Converts the var (variable) myAge to if statement
Which statement will print the content of the current directory in list format?
os.listdir()
os.listdirectory()
os.getcwd()
import os.listdir()
people = ["John", "Rob", "Bob"]
print (people[1])
what would this result be?
print("Hello world!\nHello world!")
Hello world!
The correct way to convert user input is:
birth_year = number(input())
birth_year = int(input())
birth_year = (input(int))
birth_year = int(input)
Python is _____ sensitive which means you must use the same indentation every time.
space
colour
code
word
You assign a value to a variable with which symbol
@
==
=
*
What is an instruction?
A box in a flowchart
A calculation performed in a programming language
One or more statements grouped together to instruct the computer to perform a task
A separate file that has information on how to install the program
Patients visit hospital everyday. You want to count for the "new patients" for each day. Which one is not necessary?
Set
While loop
For loop
Set difference
What will be the output?
name = 'Ralph'
greeting = "Good Bye" + name
print (greeting)
Good bye 'Ralph'
Good bye Ralph
Greeting
Good bye + Ralph
Which has integer data type?
Phone number
Zip code
HN
Number of students in the class
What is the output of the following program?
Yes
No
Error
No output
How do we get user input from the keyboard?
input = (What is your name?)
input = What is your name?
output = ("What is your name?")
input("What is your name? ")
holds whole numbers
holds a decimal point in a number
What is the output of the following program?
for i in range(0, 5):
print(i)
i=i+1
1 to 5 numbers
1 to 4 numbers
0 to 4 numbers
0 to 5 numbers
Displays the abbreviated month name:
%m
%b
%a
%d
What is the output of the following program?
1 to 10 numbers
1 to 5 numbers
1
5
A FOR loop is....
A COUNT controlled loop
A CONDITION controlled loop
Which function/command returns the current date and time?
datetime.now()
.now()
timedelta.now()
.today()
What function/command returns the current date
datetime()
.now()
.currentdate()
.today()
If the coding steps are in the incorrect order, the computer can still execute the program.
True
False
Which rounding function will produce the following input 43.5 = 44
floor
ceil
trunc
round
Which word completes this sentence: "Iteration makes code more ___________"
Complex
Efficient
Simple
Straightforward
Deletes the first matching value from the list
.add
.remove()
.pop()
.del()
If you want multiple options for your code, what should you use (after if)?
elif
else
if
from datetime import date
dt = date(month = 10, day = 23, year = 2021)
print(dt.strftime("%b %d, %Y"))
What is the correct output?
Tues, Oct 23
10/23/21
Oct 23, 2021
23 Oct 2021
What would the output be for the code shown here?
0,1,2,3,4,5,6,7,8,9
1,2,3,4,5,6,7,8,9,10
0,2,4,6,8,10
0,2,4,6,8
Moves the pointer to the beginning of the file
.seek(0)
.write
'w' and 'w+'
.strip()
Which decision statement will be triggered if the variable x is less than 20?
if x > 20:
if x <> 20:
if x == 20:
if x < 20:
Which data type would you use for the quantity of stock in a shop?
integer
float
string
boolean
A WHILE loop is....
A COUNT controlled loop
A CONDITION controlled loop
Clara is writing a program that will print out the first ten numbers of a times table (chosen by the user). Should she use....
a FOR loop
a WHILE loop
What function/object represents a duration or difference between two dates or times
timedate
timedelta
datetime
datedelta
if you receive a NameError when you run your program it means....
A variable has been assigned before it has been referred to
An incorrect name has been chosen
A variable has been referred to before it has been assigned
A language key word has been used
If you want to change the data type to an integer which line of code would you use?
int ("How much pocket money do you have?")
input("How much pocket money do you have?")
int(input("How much pocket money do you have?"))
int = ("How much pocket money do you have?")
If you want more than one option for your code, what do you use (after if)?
elif
else
ifif
if
The code you use to receive and input from the keyboard
enter()
add()
receive()
input()
Which operator can be used to compare two values?
==
<>
=
><
from datetime import time
t = time(17, 39, 10, 43)
print(t.strftime("%I:%M:%S %p"))
What is the correct output?
17:39:10 PM
17:39:10
05:39:10 PM
05:39:10 AM
From where to start the pointer before offset
.seek()
.pop()
range()
.seek(whence)
num1 = 3
num2 = "8"
What is the minimum code to mathematically add num1 to num2?
num1 + str(num2)
num1 + int(num2)
int(num1) + int(num2)
int(num1) + str(num2)
A string
carries out an action
the elements of a command
a collection of characters
how elements in a commad are arranged
What would the output of this code be if the user entered the value 70?
Pass
Fail
Merit
Distinction
