WorksheetsCP 1 Review 2023
Total questions: 37
Worksheet time: 19mins
Which version of Python are you learning in this course?
3
2
1
Any version will work equally well
Which of the following best describes an Integrated Development Environment (IDE)?
Software that helps you create and run code
Software that helps you design programs before you start coding
Software that helps you create audio, video, and images for your program
Software that helps you track your program sales
What character do you place at the end of a line to break a long statement across multiple lines?
A backslash (\)
A hash-tag (#)
A colon (:)
An extra space
Which of the following variable names are valid in Python?
All of these are valid
Testing123
testing_123
TESTING
Which of the following statements will add 10 to the value in the "mystery" variable and store the answer in the "result" variable?
result = 10 + mystery
mystery = result - 10
result = mystery(10)
mystery + 10 = result
Given a variable named "mystery", which of the following statements will display the data type of that variable?
print(type(mystery))
print(mystery
) mystery.type()
No such statement exists
What is the printed output from the following statement? print("Testing" + "Testing")
TestingTesting
Testing Testing
class 'str'
An error message
What is the displayed output when the following statement is run? print("phone","number",sep="#")
phone#number
phone number
phonenumber
"phone" on one line and "number" on the next
What is wrong with the following code?
ageInYears = input("How old are you? ") ageInDays = ageInYears * 365
ageInYears is a string and can't be used in a mathematical expression
* is not the correct symbol for multiplication
The question inside the input() parentheses should not be surrounded by double quotes
input() is missing a required timeout parameter
What text is displayed on output by the following statement? print(str.format("#{0:4}#", "dog") ) #dog # #dog# dog
#dog #
#dog#
Dog
##
Which of the following comparison operators means "not equal to"?
!=
<
>=
!<>
What will be output to the screen when the following code is run?
secret = 50
if (secret == 100):
print("Excellent")
elif (secret < 75):
print("Awesome")
else:
print("Super")
Awesome
Excellent
Super
None of these is true
Which of the following operators will produce a True result only if both joined expressions are True?
and
or
not
!=
What type of value is held in the "answer" variable after the following code runs? answer = (1 + 5) >= (6 - 1)
Boolean
Integer
Floating point
String
Which of the following is the best example of a runtime error?
An incorrectly written mathematical expression provides the wrong result
A missing parentheses in the source code
A missing double-quote around a string value
A comment is not started with the hashtag (#) symbol
Which of the following best describes a program trace?
A temporary print() statement that gives you clues as to how the program is running
An input() statement that lets the user enter debugging information
The leftover data stored in memory after the program finishes running
The process you go through to find a program that meets your needs
Which of the following is NOT a common Python debugger command?
fix (f)
step (s)
continue (c)
All of these are common debugger commands
Which of the following best describes the difference between a list and a tuple?
List contents can be changed, while tuple contents cannot be changed after the tuple is initialized
Lists can store any data type, while tuples are restricted to a single data type
Lists can store small numbers of elements, while tuples are better at storing larger data sets
Nothing is different; lists and tuples are just two names for the same thing in Python
Which of the following list functions will NOT work on a tuple?
pop()
index()
count()
These will all work on a tuple
What is the output of the following code?
hobby = "marbles"
for letter in hobby:
print("#" + letter,end="")
#m#a#r#b#l#e#s
Marbles
#######
Syntax error; you cannot iterate over the letters in a string using a "for" loop
Which keyword would you use to halt the current loop iteration and immediately continue at the top of the loop again?
continue
break
return
Jump
How would you display the value of a variable holding a date, time or datetime object in a simple, default format?
Pass the variable name into the print() function as a typical parameter
Write the variable name, then a dot and then the print() function
Write the variable name, then a dot and then the toString() function
Call the timeString() function and pass in the variable name
Which of the following statements will successfully build a date object that holds the current date?
rightNow = datetime.date.today()
rightNow = datetime.datetime.current()
rightNow = today(date)
rightNow = datetime.current(date)
What is the effect of calling random.shuffle() on a list?
The items in the list are re-ordered randomly
Each item in the list gets a new random value
The items in the list are sorted from smallest to largest
A random number of items in the list are removed completely
Which of the following is a constant value defined by the Python math library?
Both of these are true
Math.pi
math.e
Neither of these is true
What is the output when the following code runs?
food = "PIZZA"
print( len(food) )
5
4
6
Runtime exception - the len() function does not work on strings
Which of the following best describes the str.split() function?
It returns a list of individual words within a string, using white space as a default separator
It breaks a string in half and returns the first part
t copies an original string value into a new variable
It builds one new string from all of the even-numbered characters and a second string from the oddnumbered characters
If you want to ensure user input is both numeric and within a specific range, which of the following types of code should be used in the validation?
Both conditional logic and try / except protection
Conditional logic only
try / except protection only
It's not possible to restrict numeric input to a range
Given the following function definition:
def sound_horn():
print("Beep, Beep!")
How would you call this function in your code?
sound_horn()
call horn
def sound_horn()
call sound_horn()
Which of the following is true about data returned from a function?
All of these are true
You can ignore it
You can store it in a variable for later use
You can use it immediately in some other expression or statement
A function's input parameters are treated as __________ scope variables.
local
local
global
international
general
When a function is defined within a class, it is also called a ___________.
method
variable
value
Object
Given the following code, how and where would you define a method belonging to this object?
class Clock:
hour = 10
minute = 35
With a "def" statement, indented to the right underneath the "class" statement and class variable initializations
With a "function" statement located above the "class" statement
With a "def" statement below the "class" statement, aligned on the left with no indentation
With a "method" statement located above the "class" statement and indented to the right
Our online Python engine will display multiple source files in different tabs. Which tab is always used as the main program code that will run first?
The left-most tab
The right-most tab
The tab with the asterisk (*) next to it
The tab that you double-click on to start the program
Given the code below, which of the following answers will create an instance variable named "treat" on the object held in the "myDog" variable?
class Dog:
def speak():
print("WOOF")
myDog = Dog()
myDog.treat = "Bone"
Dog.treat = "Bone"
treat = Dog("Bone")
Dog[treat] = "Bone"
Consider the class definition below. What is the purpose of the init() method?
class Dog:
def init(self, aName):
self.name = aName
To ensure an instance variable called "name" is always initialized when an object instance is created
To ensure that no code outside of the "Dog" class can access the "name" variable
To let the main program code change the Dog's name after the object is created
To create a new variable called "self" and set it equal to "name"
Which Python keyword can you assign to a variable to completely remove any object or value from that variable?
None
Clear
Delete
Void
