Final Flashcards
How would you create a blank list in Python?
x = [ ]
What would the following code display?
psycho = [22,23,24,98,100,101]
numbers[-4] = 99
print(numbers)
error numbers not defined
if psycho instead of numbers the output would be
[22,23,99,24,98,100,101]
What would the following code display?
numbers = [1,2,3,4,5]
my_list = numbers[1:3]
print(my_list)
[2, 3]
Write a program that opens an output file with the filename my_name.txt, writes your name to
the file and then closes the file.
def main(): my_file = open('my_name.txt', 'w') my_file.write("Lillian") my_file.close() main()
A file that data is written to, is known as a(n)
a. input file
b. output file
c. sequential access file
d. binary file
b. output file
This function returns the length of a list.
a. highest
b. length
c. length of
d. len
d. len
Which of the following is a count controlled loop?
a. for
b. foreach
c. while
d. erst
a. for
A group of statements that exist within a program for the purpose of performing a specific task is a(n) __________.
a. block
b. parameter
c. function
d. expression
c. function
Each repetition of a loop is known as a (n) __________.
a. cycle
b. revolution
c. orbit
d. iteration
d. iteration
he += operator is an example of a(n) __________ operator.
a. relational
b. augmented assignment
c. complex
d. reverse
b. augmented assignment
A variable that is used to mark the end of a sequence of values is known as a (n)
a. accumulator
b. counter
c. terminator
d. sentinel
d. sentinel
The first line of a function definition is known as the \_\_\_\_\_\_\_\_\_\_. a. body b. introduction c. initialization d. header
d. header
A __________ is a variable that is created inside a function.
a. global variable
b. local variable
c. hidden variable
d. none of the above, you cannot create a variable in a function
b. local variable
A __________ is a piece of data that is sent into a function.
a. argument
b. parameter
c. header
d. packet
a. argument
Briefly describe an exception
An error that causes the program to stop