Font size
WorksheetsFinal CS review Spring semester
Total questions: 157
Worksheet time: 1hrs 19mins
What is a file?
It is an object on a computer that stores data, information, settings, or commands used with a computer program.
It is an area on the computer containing other directories and files.
“cute cat.png” is the _______ of an image.
file name
file extension
file size
“.png” is the _______.
file name
file extension
file size
The computer understands that files ending with ______ are Python files.
.cs
.java
.js
.py
.html
The (a) is a user interface that is navigated by typing commands at prompts, instead of using a mouse.
What command should you use to run a Python file named hello world.py?
run world.py
python world.py
run python world.py
command .py world.py
What is the statement to display “Hello world!” using Python.
print("hello world")
print(hello world)
display("hello world")
display(hello world)
Which of these variable names is not valid in python?
&ones
turnover25
HOOP_RADIUS
short_angle
What is a string in Python?
A string is what shoes have so they don’t fall off your feet.
A string is the representation of numbers in Python.
A string is a collection of items of any data type.
A string is a series of characters.
How is a string represented in Python?
Between single quotes or double quotes.
Only using single quotes (’).
Only using double quotes (").
No option is correct.
What is the method .title() used for?
It changes a string to all lowercase.
It creates a title.
It changes each word to Title Case, where each word begins with a capital letter.
It changes a string to all UPPERCASE.
What does the method .upper() do?
It changes a string to all lowercase.
It creates a title.
It changes each word to Title Case, where each word begins with a capital letter.
It changes a string to all UPPERCASE.
What does the method .lower() do?
It changes a string to all lowercase.
It creates a title.
It changes each word to Title Case, where each word begins with a capital letter.
It changes a string to all UPPERCASE.
What do we use to format strings and use variables inside strings?
Python Lists
f-strings
The format method from Javascript
Strings between backslashes (\)
What character combination can we use to add a newline inside a string?
\n
\t
\an
\at
What character combination can we use to add a tab inside a string?
\n
\t
\an
\at
Which of the following is NOT a way to create a string and will throw an error?
message = "One of Python’s strengths is its diverse community."
’message = ’One of Python’s strengths is its diverse community.’
message = f"One of Python’s strengths is its diverse community."
message = f’One of Python s strengths is its diverse community.’
What is the symbol for addition in Python?
+
-
*
/
What is the symbol for subtraction in Python?
+
-
*
/
What is the symbol for multiplication (×) in Python?
+
-
*
/
What is the symbol for division (÷) in Python?
+
-
*
/
What is the result of the following operation: >>> 2 + 3 * 4
23333
14
234
20
What is the result of the following operation: >>> (2 + 3) * 4
23333
14
234
20
What is the result of the following operation: >>> 4/2
2/1
2.0
2
’2’
Does Python have a built-in constant type?
yes
no
How do you write a comment in Python?
comment(’Say hello to everyone’)
// Say hello to everyone
writeCommentPlease(’Say hello to everyone’)
# Say hello to everyone
What is a list?
A list is the representation of numbers in Python.
A list is a collection of items in a particular order.
A list is a series of characters.
A list is a method that we use to list the name of variables in Python.
What is the correct statement to create a list?
bicycles = [’trek’, ’cannondale’, ’redline’, ’specialized’]
python createList()
bicycles = ’trek’, ’cannondale’, ’redline’, ’specialized’
bicycles = (’trek’, ’cannondale’, ’redline’, ’specialized’)
Which of the following will access to the first element of a list?
bicycles[1]
bicycles(0)
bicycles[-1]
bicycles[0]
What is it the correct statement to modify the second element of the following list:
>>> motorcycles = [’honda’, ’yamaha’, ’suzuki’]
motorcycles[1] = ’ducati’
motorcycles[2] = ’ducati’
’ducati’ = motorcycles[2]
motorcycles[1].change(ducati)
Which statement will delete the last element of the following list?
students = ["Anna", "Alan, "Coco", "Grace"]
del students[4]
del students[-1]
students[-1].delete()
delete students["last"]
What is the result of running the following Python code?
name = "ada lovelace"
name.title()
print(name)
ada lovelace
Ada Lovelace
Ada Lovelace title
ADA LOVELACE
What is it the correct statement to add an element at the end of a list?
bicycles.append(’element’)
bicycles.insert(0, ’element’)
popped item = bicycles.pop()
bicycles.remove(’element’)
What is it the correct statement to add an element at a specific position of a list?
bicycles.append(’element’)
bicycles.insert(0, ’element’)
popped item = bicycles.pop()
bicycles.remove(’element’)
What is it the correct statement to remove an element of a list and save it in a variable?
bicycles.append(’element’)
bicycles.insert(0, ’element’)
popped item = bicycles.pop()
bicycles.remove(’element’)
What is it the correct statement to remove an element of a list using the value of the element?
bicycles.append(’element’)
bicycles.insert(0, ’element’)
popped item = bicycles.pop()
bicycles.remove(’element’)
What is it the correct statement to order a list alphabetically and permanently?
sorted(cars)
cars.sort(reverse=True)
cars.reverse()
cars.sort()
What is it the correct statement to order a list in reverse alphabetical order and permanently?
sorted(cars)
cars.sort(reverse=True)
cars.reverse()
cars.sort()
What is it the correct statement to order a list alphabetically and temporarily?
sorted(cars)
cars.sort(reverse=True)
cars.reverse()
cars.sort()
What is it the correct statement to reverse the order of a list?
sorted(cars)
cars.sort(reverse=True)
cars.reverse()
cars.sort()
How you can find the length of a list?
cars.len()
len cars
len(cars)
cars.find(’length’)
What is the correct syntax for the "for" loop?
for magician in magicians:
for each magician in magicians:
for magicians of magician:
for magician of magicians:
What error will throw python interpreter with the code that you can use on the image?
IndentationError: expected an indented block
IndentationError: unexpected indent
SyntaxError: invalid syntax
ZeroDivisionError: division by zero
What error will throw python interpreter with the code that you can use on the image?
IndentationError: expected an indented block
IndentationError: unexpected indent
SyntaxError: invalid syntax
ZeroDivisionError: division by zero
What error will throw python interpreter with the code that you can use on the image?
IndentationError: expected an indented block
IndentationError: unexpected indent
SyntaxError: invalid syntax
ZeroDivisionError: division by zero
Which is the function that makes easy to generate a series of numbers?
range()
len()
list()
random()
What numbers will generate the following statement?
range(1, 5)
1 2 3 4
0 1 2 3
1 2 3 4 5
0 1 2 3 4
Which function can we use to convert the result of a range() into a list?
range()
len()
list()
random()
What is it the statement to make a list of the numbers from one to one million?
list(range(1,1000001))
list(range(1,1000000))
list(range(0,1000001))
list(range(0,1000000))
Which is the function to find the minimum of a list of numbers?
min()
max()
sum()
len()
Which is the function to find the maximum of a list of numbers?
min()
max()
sum()
len()
Which is the function to find the sum of a list of numbers?
min()
max()
sum()
len()
What is the name of a a specific group of items in a list?
slice
small group of a list
listy
comand
If we have the following list:
players = ['charles', 'martina', 'michael', 'florence', 'eli']
What will be the output of the following statement:
print(players[0:3])
['charles', 'martina', 'michael']
['martina', 'michael', 'florence']
['charles', 'martina', 'michael', 'florence']
['michael', 'florence', 'eli']
If we have the following list:
players = ['charles', 'martina', 'michael', 'florence', 'eli']
What will be the output of the following statement:
print(players[1:4])
['charles', 'martina', 'michael']
['martina', 'michael', 'florence']
['charles', 'martina', 'michael', 'florence']
['michael', 'florence', 'eli']
If we have the following list:
players = ['charles', 'martina', 'michael', 'florence', 'eli']
What will be the output of the following statement:
print(players[:4])
['charles', 'martina', 'michael']
['martina', 'michael', 'florence']
['charles', 'martina', 'michael', 'florence']
['michael', 'florence', 'eli']
If we have the following list:
players = ['charles', 'martina', 'michael', 'florence', 'eli']
What will be the output of the following statement:
print(players[2:])
['charles', 'martina', 'michael']
['martina', 'michael', 'florence']
['charles', 'martina', 'michael', 'florence']
['michael', 'florence', 'eli']
What is the correct statement to copy the following list list?
my_foods = ['pizza', 'falafel', 'carrot cake']
friend_foods = my_foods[:]
friend_foods = my_foods
friend_foods = copy(my_foods)
my_foods.copy(friend_foods)
What is the main difference between a tuple and a list?
Tuples cannot be change and list can.
Tuples only can have 2 elements.
Tuples can be change and list cannot.
There isn't a method to create tuples.
What is the output?
True
False
condition1
condition2
What is the output?
next
stop
next
stop
syntax error - program doesn't work
What is the output?
True
NIL
True
NIL
True
NIL
NIL
What will be outputted?
number is bigger than 10
nothing
an error
NUMBER IS BIGGER THAN 10
How do we call the condition inside the if statement that can be evaluated as True or False?
conditional test
slice
python evaluation
logical operator
How do we check if a value is in a list?
Using the "for" loop.
Using the "in" keyword.
Using the function isIn().
There is no way to check that.
Consider the following statement:
If you just need to work with the keys of a dictionary, then you can use .keys(), which is a method that returns a new view object containing the dictionary’s keys.
Is this statement True or False?
False
True
Which of the following create an empty dictionary called person?
person = dict()
person = ()
person = []
person = {}
quiz = {"Do you help out at home? ":"yes",
"Do you beleive in Santa? ":"yes"}
list
string
dictionart
dictionary
quiz = ("Do you help out at home? ":"yes" }
Which is the correct statement to delete a key-value pair from a dictionary called alien_11?
alien_11.delete()
alien_11.discard()
alien_11.remove()
del alien_11['keyName']
________________method will return the number of key-value pairs in the given dictionary.
len( )
pop( )
del( )
keys( )
values( )
How much information can a dictionary store in python?
Almost limitless amount of information.
Less than 1 Kilobyte.
A very limited amount of information.
A infinite amount, a dictionary can contain all the data in the world and more.
What is it a dictionary in python?
It is a collection of key-value pairs.
It is the representation of numbers in Python.
It is a set of values associated with each other.
It is a series of characters.
What is it a key-value pair?
It is a collection of key-value pairs.
It is the representation of numbers in Python.
It is a set of values associated with each other.
It is a series of characters.
What type of data can it be a key value?
A key’s value can be a number, a string, a list, or even another dictionary.
A key’s value only can be a number.
A key’s value only can be a string.
A key’s value only can be a list.
How many key-value pairs does the following dictionary have?
alien_0 = {'color': 'green', 'points': 5, 'power': 50}
(a)
Can you add new key-value pairs to dictionaries?
Yes
No
Does python allow you to loop through a dictionary?
Yes
No
What method can we use to print all the key-value pairs of a dictionary as a list?
items()
keys()
values()
set()
What method can we use to loop through all the keys of a dictionary?
items()
keys()
values()
set()
What method can we use to loop through all the values of a dictionary?
items()
keys()
values()
set()
What function can you use to loop through all the values of a dictionary avoiding duplicated values?
items()
keys()
values()
set()
What is nesting in python?
It is a natural instinct experienced by many expecting mothers, most commonly in the last trimester.
Are dynamic structures, and you can add new key-value pairs
to a dictionary at any time.
It is to store multiple dictionaries in a list, or a list of
items as a value in a dictionary.
What is the correct way to declare a function in Python?
function myFunc():
def myFunc():
var myFunc():
func myFunc():
What is the correct way to call a function in Python?
function myFunc()
myFunc()
call myFunc()
myFunc.call()
What is a default argument in a function?
An argument that is required to call the function.
An argument that is optional to call the function.
An argument that is used to define the function.
An argument that is returned by the function.
What is a parameter in a function?
A variable that is only available inside the function.
A value that is returned by the function.
A value that is passed to the function when it is called.
A value that is stored in the function.
What is the purpose of a return statement in a function?
To stop the execution of the function.
To print a message to the console.
To return a value from the function.
To define a new function.
How do you define a function in Python?
By using the keyword "define".
By using the keyword "function".
By using the keyword "def".
By using the keyword "return".
What is a function in Python?
A loop that repeats a set of instructions.
A way to store and manipulate data.
A block or a piece of code that performs a specific task.
A data structure that stores values.
What is the hash sign?
#
@
&
*
What is the representation of the hyphen?
/
|
&
-
What is the representation of underscore?
/
|
_
+
What is the representation of the parenthesis?
<>
{}
[]
()
What is the representation of the square brackets?
<>
{}
[]
()
What is the representation of the colon?
,
:
;
.
What function do we use to ask for input to the user?
input()
len()
print()
list()
name()
What is a folder?
It is an object on a computer that stores data, information, settings, or commands used with a computer program.
It is an area on the computer containing other directories and files.
What is the purpose of the open() function in the program?
The open() function is used to access the file.
The open() function is used to now if the existence of a file, but you cannot work with it.
The open() doesn't exist in python.
The open() method is used to read the entire contents of a file.
What is the purpose of the with keyword when opening a file?
The with keyword closes the file once access to it is no longer needed.
The with keyword doesn't exist in python.
The with keyword allows you to access more than one file at the same time.
The with keyword allows you to handle exceptions when working with files.
Why is it not necessary to call the close() method after opening and reading a file using the with keyword?
With the with keyword, Python will automatically close the file when the with block finishes execution, so it's not necessary to call the close() method.
Because a bug in your program prevents the close() method from being executed, the file may never close. This may seem trivial, but improperly closed files can cause data to be lost or corrupted.
Python is smart enough to close the files one you are not longer need them, so you never need to use close().
Because it is not nesecery to close a file, you can leave it open and nothing will happend.
What method is used to read the entire contents of a file?
The read() method is used to read the entire contents of a file.
The read() method is used to overwrite the entire contents of a file.
The read() method is used to append new text in a file.
The read() method is used to create a new file.
What directory does Python look in by default when you pass a simple filename to the open() function?
Python looks in the directory where the file that’s currently being executed is stored.
Python stop running and throw and error because there is not default directory.
Python looks in the parent directory where the file that's currently being executed is stored.
Python will display a message asking in wich directory you want to open the file and the user will have to input the directory name.
What is a file path?
A file path is a specific location on your system where a file is stored.
A file path is a variable that you can use to store information about the python program.
A file path is the name of a software application used to manage files on your computer.
A file path is a numerical code assigned to each file on a computer for identification purposes.
What is a relative file path?
A relative file path tells Python to look for a given location relative to the directory where the currently running program file is stored.
A relative file path is a numerical code assigned to each file on a computer for identification purposes.
An relative file path specifies the full path to a file, regardless of the location of the currently running program file.
A file path is the name of a software application used to manage files on your computer.
What is an absolute file path?
An absolute file path specifies the full path to a file, regardless of the location of the currently running program file.
An absolute file path tells Python to look for a given location relative to the directory where the currently running program file is stored.
An absolute file path is a numerical code assigned to each file on a computer for an absolute identification process.
An absolute file path is a Large Language Model.
Why might you want to assign an absolute path to a variable before passing it to the open() function?
Because make the code easier to read and modify.
Because the code won't work otherwise.
Because you have to convert the path into a string before using the open() function.
Because that way you can close the file when you finish working with it.
Why can't you use backslashes in a file path on Windows systems?
Because they may be interpreted as escape sequences instead of as part of the path.
There is no problem in using backslashes in Windows systems.
Because the python program will be more efficient.
Because will make the code more difficult to read and edit.
What method can you use to store the lines of a file in a list?
The readlines() method.
The read() method.
The lines() method.
The readEachLine() method.
How can you print the lines of a file from a list?
You can use a for loop to print each line from the list.
You should create a class file first.
Using inheritance.
You can use a for loop before reading the file.
What do you need to do if you want to work with numerical values that are read from a text file?
You'll need to convert them to an integer using the int() function or to a float using the float() function.
Nothing, python will convert automatically the string into a number.
You'll need to convert them to a number using the toNumber() function.
You'll need to create a new instance of the class Integer() or Float() passing the input of the file.
Is there a limit to how much data you can work with in Python?
As much data as your system's memory can handle.
More data than your system's memory can handle.
It is limited by python.
264TB of data.
What is one of the simplest ways to save data?
Write it to a file.
Creating a list.
Using a tuple.
Declaring an instance of the Save class.
How do you write text to a file?
You need to call open() with a second argument telling Python that you want to write to the file.
You need to call open() and use the method write.
You need to use the class File and the method write().
You need to call open() and using dot notation tell Python that you want to write to the file.
What is the second argument in the call to open() used for?
It tells Python what mode to open the file in.
It tells Python what ASCII code we want to use for the file.
It tells python how many files it has to find in the directory.
It tells python when do you want to close the file.
What are the different modes you can use to open a file?
In read mode, write mode, append mode, or a mode that allows you to read and write to the file.
Only in read and write mode.
In read mode, write mode or a mode that allows you to read and write to the file.
In read mode, append mode, or a mode that allows you to read and write to the file.
What happens if you open a file in write mode ('w') that already exists?
Python will erase the contents of the file before returning the file object.
Python will throw and exception and we can handle it with a try-except block.
Python will keep the old file so we don't lose information.
Python will throw and exception that cannot be handle with a try-except block.
What method do you use to write on a file once it is opened?
writeLine()
write()
open()
with()
What should you do if you want to store numerical data in a text file?
Convert the data to string format first using the str()
Nothing, python will convert automatically the numerical data into a string.
You'll need to convert them to a number using the toText() function.
You'll need to create a new instance of the class String() passing the numerical data you want to convert.
What happens if you write multiple lines without including newline characters?
The lines will be squished together in the file.
Python will include automatically the newline characters for you.
Python will throw and exception.
The lines will cause a logical error the you won't notice.
How do you add content to a file without overwriting existing content?
Opening the file in append mode.
Just open the file and write in it.
Opening the file in write mode and then use the append() method.
You cannot write in a file without overwriting.
What is the difference between opening a file in write mode and opening it in append mode?
In write mode, Python overwrite the existing content. In append mode, any line will be added at the end of the file.
There is no difference.
In write mode, any line will be added at the end of the file. In append mode, Python overwrite the existing content.
There is only the write mode. The append mode does not exist.
What are exceptions in Python?
They are special objects used to manage errors that arise during a program's execution.
They are instances of the class Error.
They are special objects used only to check if a file exist or not in a specific directory.
Exceptions doesn't exist in Python
What happens if an exception is not handled?
The program will halt and show a traceback, which includes a report of the exception that was raised.
Nothing, Python will continue running as normal.
The program will show syntax Error.
The program will show identation Error.
How are exceptions handled?
Exceptions are handled with try-except blocks.
Exceptions are handled with the Try class which inherits from the Error class.
Exceptions are handled automatically by Python.
Exceptions cannot be handle.
What error does Python raise when dividing a number by zero?
A ZeroDivisionError exception.
A NumberError exception.
A SyntaxError exception.
A MathOperatorError exception.
When should you use a try-except block?
When you anticipate that an error may occur.
In all the function and methods.
At the beginning of the init () method of a class.
When you open() a file in write mode.
What is the purpose of a try block in a try-except block?
Run the code that might raise an exception.
Handle the specific type of exception.
Try to open a file that might not exist.
Doesn't have a purpose.
What is the purpose of an except block in a try-except block?
Run the code that might raise an exception.
Handle the specific type of exception.
Try to open a file that might not exist.
Doesn't have a purpose.
What happens if an exception is raised in a try block?
Python looks for an except block whose error matches the one that was raised and runs the code in that block.
Python stops running.
We try to run the code in the try block.
We use the pass keyword to handle the error.
What does JSON stand for?
For JavaScript Object Notation.
For Java Object Notation.
For Jason Object Notation.
For Java Oriented Notification.
What arguments does the json.dump() function take?
It takes two arguments: a piece of data to store and a file object it can use to store the data.
It takes one arguments: a piece of data to store.
It does not take arguments.
It takes two arguments: a file object it can use to store the data and a absolute file path.
What is my_dog in the given code snippet?
my_dog = Dog('blacky', 2)
A method that initializes the dog object.
A variable representing the name of the dog.
An instance of the Dog class.
An attribute storing the dog's age.
How do you access classes when importing an entire module?
Use the syntax module_name.class_name
Use the syntax class_name.module_name
You cannot import and entire module.
Use the syntax module_name -> class_name
What is a method in Python?
A built-in Python keyword used to define classes.
A data type that stores a collection of values.
A function that's part of a class.
A statement used to control the flow of execution in a program.
What happens if you only use one underscore before and after the method init()?
The method won't be called automatically when you use your class.
Nothing, everything will work OK.
What happens when you create multiple instances of a class in Python with the same arguments?
Only the last instance created will retain the attribute values.
Each instance will have its own unique memory address and separate attribute values.
The program will throw an error indicating duplicate instances.
Each instance will have the same memory address but separate attribute values.
What attributes are included in the Dog class?
class Dog:
def init(self, name, age):
self.name = name
self.age = age
def sit(self):
print(f'{self.name} is now sitting.')
def roll_over(self):
print(f'{self.name} rolled over!')
name and age
only name
only age
the class dog has no attributes
How do you access the attributes of an instance in Python?
By using the getattr() function (getattr(instance, 'attribute'))
By using square bracket notation (instance['attribute'])
By calling a method with the attribute name as an argument (instance.get_attribute('attribute'))
By using dot notation (instance.attribute)
How can you import all classes from a module?
from module_name import [:]
from module_name import ()
from module_name import module_name.importAll()
from module_name import *
What happens when one class inherits from another class?
The child class can only access the public attributes and methods of the parent class.
The child class gains access to all attributes and methods of the parent class.
The parent class is deleted and replaced by the child class.
The parent class becomes an instance of the child class.
What is the naming convention for classes and instances in Python?
Classes and instances both use lowercase letters with underscores.
Classes are typically named using CamelCase, while instances use lowercase letters with underscores.
There isn't a convention.
Classes and instances both use UPPERCASE letters with underscores.
What must be included in parentheses in the definition of the child class so we know which class is the parent?
The parent class name.
The child class name.
The memory reference of the parent class.
Nothing.
What are attributes in Python?
Variables that are accessible through instances.
Data structures used to store and manipulate collections of items.
Methods that perform specific actions on objects.
Reserved keywords used to define loops and conditional statements.
What is it called when you make a new thing from a class?
string
data tape
parent class
instantiation
How can you make sure that each instance of a class is unique in Python?
By providing a unique identifier as an argument when creating each instance.
By giving to each instance a different name.
By implementing a custom eq method in the class to compare instances for uniqueness.
By using a class variable to track and enforce uniqueness during instance creation.
If you store multiple classes in a single module, what should they be?
They should be related somehow.
They should have identical attributes and methods.
They should be randomly chosen and not have any logical connection.
They should be completely unrelated and serve different purposes.
Which class must appear before, the child class or the parent class?
The order doesn't matter.
The child class.
The parent class.
They must be in different files.
What method do you use in the init() method from the child class to call the __init__() method of the parent class?
super().__init__()
parent.__init__()
self.parent.__init__()
child.__init__()
What is a docstring?
A docstring is a string literal that appears as the first statement in a module, function, class, or method definition.
A docstring is a variable that stores the contents of a module.
A docstring is a special function that retrieves information about the module.
A docstring is a keyword used to define the type of a variable or function.
What is the parameter self, that is pass to all the methods of the class?
It is a variable that you must pass when creating a instance of the class.
It is a parameter used to specify the return value of the method.
It is a keyword that defines the method as a special type of function.
It is a reference to the instance itself.
How many instances of a class can you create in Python?
There is no limit to the number of instances of a class that can be created.
You can create multiple instances of a class, but there is a limit.
Only one instance of a class can be created.
The number of instances you can create is limited by the number of attributes defined in the class.
What is it the init() method?
It is a special method that Python runs automatically whenever we create a new instance based on a class.
It is a method to create a string in python.
It is a method to display data in python.
It is one of the most effective approaches to writing software.
What should you do if a class in one module depends on a class in another module?
Modify the first module to include the code of the required class directly.
Create a new instance of the required class within the first module.
Import the required class into the first module.
Modify the first module to include the code of the required class directly
What is object-oriented programming?
It is a collection of key-value pairs.
It is a collection of data that is stored electronically.
It is one of the most effective approaches to writing software.
It is a collection of items of any data type.
How do you import multiple classes from a module?
You use a wildcard character (*) to import all classes from the module.
You import each class individually using separate import statements.
You separate each class with a comma.
You wrap the classes in square brackets and import them as a list.
What behaviors are included in the Dog class?
class Dog:
def init(self, name, age):
self.name = name
self.age = age
def sit(self):
print(f'{self.name} is now sitting.')
def roll_over(self):
print(f'{self.name} rolled over!')
only roll_over()
the class dog has no behaviors
sit() and roll_over()
only sit()
