python midterm
The first index of any sequence, such as a list, is at index _____
0
What is the output of the following program segments? counter = 0while counter <5: counter += 1print(counter, end = " ")
5
What is the output of the following program segment? bonus = 500.0sales = 2000.0if sales > 2000.0: bonus += 250 print("Bonus: ", bonus)
Bonus: 750.0
Output files do not need to be opened. When you write to them, they are automatically opened.
False
How many iterations will the following loop structure execute?loops = 1userInpt = 10while(loops != userInpt): print(loops) loops += 2
Infinitely many
function body
The part of a function that contains the commands jumble = ""while len(word) > 0: index = random.randint(0, len(word) - 1) jumble += word[index] word = word[ : index] + word[index + 1: ]return jumble
User Defined Functions
These are similar to procedures and must also be defined and given a name before it can be used in the program but it can only return a single value to the program. jumble = jumbleWord(word)
You can have more than one except clause in a try / except statement.
True
What is the output of the following program segment? n1 = 27n2 = 18rem = 1n3 = 1while rem != 0: rem = n1 % n2 if rem == 0: n3 = n2 else: n1 = n2 n2 = rem
Value of n3 is 9
This method will add items to the end of the list.
append
When a file is opened in this mode, data will be written at the end of the file's existing contents.
append mode
A(n) ________ is a piece of data sent to a function during the function call
argument
When a program is finished using a file, it should do this
close the file
The statement if age < 13 then movieTicket = 4.00, else movieTicket = 8.00 is an example of which programming structure?
dual alternative decision structure
A group of statements that exist within a program for the purpose of performing a specific task is a(n) _________.
function
Before a file can be used by a program, it must be _______
opened
A(n) _________ is a special variable that receives a piece of data when a function is called
parameter
This method will remove an item from a list at a specific index
pop
This marks the location of the next item that will be read from a file.
read position
The symbols >, <, == are all ______ operators
relational
Given values2D = [ [3, 2, 1] , [4, 5, 1], [9, 2, 4], [ 2, 3, 6] ] What does len(values2D) return
return 4
given that values = [0, 2, 4, 6, 8] what does len(values) return?
returns 5
The statement if age >= 65 then seniorDiscount = "yes" is an example of which programming structure?
single-alternative selection
function header
the first line in a function; marks the beginning of the function def jumbleWord(word:str) -> str:
You write this statement to respond to exceptions.
try/except
what value creates a tuple
value = (1, 2, 3) round brackets
Given values2D = [ [3, 2, 1] , [4, 5, 1], [9, 2, 4], [ 2, 3, 6] ] What does print(values2D[2][1]) display
value of 2
Given values2D = [ [3, 2, 1] , [4, 5, 1], [9, 2, 4], [ 2, 3, 6] ] What does print(values2D[3][0]) ?
value of 2
Given values2D = [ [3, 2, 1] , [4, 5, 1], [9, 2, 4], [ 2, 3, 6] ] What does len(values2D[-1]) return
value of 3