Font size
WorksheetsMidterm spring 2023 review
Total questions: 100
Worksheet time: 51mins
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 returns 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 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.
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)
1. Underline the keys of the following dictionary’s key-value pairs.
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.
