cs 171 final😔🤘🏽
What symbol is used to denote comments in a Python program?
#
Fill in the Blank with the best option item = 'car' price = 35000 print('The %s is ____' % (item, price))
%d
Fill in the Blank item = 'car' price = 35983.30 print('The %s is ____' % (item, price))
%f
Fill in the Blank item = 'car' price = 35000 print('The ___ is %d' % (item, price))
%s
def f(x, y): print( "f(%d, %d)" %(x, y) ) if y == 0: return x else : m = f(y, x % y) return m f(49, 104) Complete the output of the program to the console below. f( [A1], [A2] ) f( [A3], [A4]) f( [A5], [A6]) f( [A7], [A8]) f( [A9], [A10])
(49,104) (104,49) (49,6) (6,1) (1,0)
The output of the statement 'Eagles'.find('L') would be
-1
What Integer is represented by the binary Two's Complement value 1010 1010?
-86
What Integer is represented by the binary value 0000 0000?
0
def print_face(): print("Printing") print_face() print_face() How many function definitions of print_face are there?
1
What is the result of float(1.55)
1.55
What Binary represented by the integer value 154?
1001 1010
Given the following list: [ 43, 44, 91, 8, 59, 10, 64, 81, 94, 13, 3 ] How many list elements will be compared if the search key is 3 using linear search? Enter a number (e.g. 1)
11
What Two's Complement Binary representation of the integer -32?
1110 0000
How many times will the print statement execute? for i in range(6): for j in range(3, 5): print(""Hello!"")
12
What does the following code print? def pizza_maker(size, topping, *extra): print('%s inch pizza with %s' % (size, topping), end=' ') for other in extra: print(other, end=' ')pizza_maker('16', 'pepperoni', 'mushrooms')
16 inch pizza with pepperoni mushrooms
Given the following list: [ 4, 11, 17, 18, 25, 45, 63, 77, 89, 114 ] We are using binary search and our key is 17. What is the third value the key is compared against? Enter a number (e.g. 4)
17
Quick sort divides an array into how many sub lists?
2
The return value for 'ABACA'.find('A',1) will be?
2
What is the result of 9 // 4?
2
Given the following list: [ 2, 5, 7, 10, 12, 15, 20, 22, 25, 70 ] We are using binary search and our key is 19. What is the second value the key is compared against? Enter a number (e.g. 4)
22
Given the following list: [ 4, 11, 17, 18, 25, 45, 63, 77, 89, 114 ] How many list elements will be compared to find 17 using binart search? Enter a number (e.g. 1)
3
Given the following list: [ 9, 15, 17, 38, 40, 45, 62, 73, 86, 134 ] How many list elements will be compared if the search key is 17 using binary search? Enter a number (e.g. 1)
3
What do you expect as the output for the statement '%.2f' % 3.14159
3.14
How many times will the loop body of the following code execute? x = 3 while x <= 6 # Do something x = x + 1
4
What will be the output for '%d' % 5.9?
5
What is the value of result after the following code is executed? def f(n): if n == 4: return 1 else: return 3*n+f(n-1) result=f(7)
55
Given the following list: [ -1, 4, 630, 810, 9, 490, 30, -67, 1, 69, 602 ] How many list elements will be compared if the search key is 490 using linear search? Enter a number (e.g. 1)
6
What sequence is generated by range(6, 1, -2)?
6 4 2
Which symbol is used to assign a value to a variable?
=
What is the purpose of the following recursive function? def mystery(myList, start, stop, count): if start == stop: return count else:c = myList[start] % 2 if c == 0: count += 1 return mystery(myList, start + 1, stop, count) else: return mystery(myList, start + 1, stop, count)
Find the number of even values in a list
What is i = i + 1 equal to?
I += 1
A function's ability to add/multiply different types of objects is called
Polymorphism
To search for modules in directories other than the current directory, we modify the ________
Pythonpath environmental variable
What kind of error is caused when you violate the programming language's rules?
Syntax error
What is the purpose of the following recursive function? def mystery(a, b): if a > b: return 1 else : return a * mystery(a + 1, b)
To calculate the product of all numbers from a to b
All data stored in a computer's memory is in binary. T or F?
True
Which loop is preferred in a situation when the number of iterations is not computable before entering the loop?
While loop
Given the following list: [ 20, 3, 18, 15, 25, 7, 34, 11 ] Which of the following would accurately show the list after the third pass of the selection sort algorithm?
[3, 7, 11, 15, 25, 20, 34, 18]
Which special symbol is used to print a newline in a string?
\n
What variable name can be used to determine if a file is being run as a script or module?
_name_
Which of the following is a valid variable name?
_x_
Which of the following is a valid compound operator?
a += 1
What does the following code print? def modify(my_string): my_string += 'def'my_string = 'abc'modify(my_string)print(my_string)
abc
The current contents of my_file.txt are: abc What will my_file.txt look like after this code block is executed: f = open('myfile.txt', 'a') f.write('abc\n')
abc abc
Given my_str = 'philadelphia', what would my_str[::-2] return?
ahldlh
What is a sequence of instructions that solves a problem?
algorithms
name = 'abcd' print (name[1]); Output of above code is:
b
Data is stored in a computer's memory using what system?
binary
For a file object my_file opened in binary mode, my_file.read() returns a ____
bytes object
Base 10 representation of a number is known as what type of representation?
decimal representation
The help() function prints the __ for a function.
docstring
Python uses _____ typing
dynamic
When passing arguments containing spaces through command line, the user should _____.
enclose argument with quotes
A Programmer should write the entire program before testing whether the program works. T or F?
false
Python code can be loaded from other files using the #include command. T or F?
false
What is the value of result after the following code is run? a = True b = False c = False result = b and c and not c
false
What is the value of result after the following code is run? a = True b = False c = False result = c and a or not a
false
What is the value of result after the following code is run? a = True b = True c = True result = a and not b or not a
false
What data type does the / operator return?
float
What programming structure best solves the following problem? Apply a 10% discount to all the prices stored in a List
for loop
What programming structure best solves the following problem? Print all values in the range(0,21)
for loop
Match the following for loop with the while loop that produces the exact same output. for i in range(0, 6): print(i)
i = 0 while i <= 5: print(i) i += 1
In Python, strings are ___ objects
immutable
Which of the following commands would allow a script to use code from a file named example.py
import example
What is a loop that will always execute because the loop's expression is always True?
infinite loop
What data type is the variable a in the following statement a = 13
integer
What data type is the variable a in the following statement? a = 24
integer
What data type is the variable a in the statement a = int(input()) ?
integer
What is the program that executes code written in Python called?
interpreter
Which method can be used to return a new set with the shared elements between the two sets?
intersection()
Each time through a loop's statement is called a/an?
iteration
Which of the following is not found in the Math Module?
len
What data type is the variable a in the following statement a = [2, 12, 9]
list
What data type is the variable a in the following statement? a = [13, 6, 3]
list
What data type is the variable a in the following statement? a = [2, 0, 7]
list
Variables created inside of a function are ___ variables
local
What is a variable to count the number of iterations called?
loop variable
Given my_str = 'AAAAA', to obtain the value for my_str2 as 'BBBBB', what statement should be used?
my_str2 = my_str.replace('A','B')
What command can be used to make an identical copy my_str2 of an existing string my_str1?
my_str2 = my_str1[:]
What is num = num + num * 2 equal to?
num += num*2
What function converts a character to its numerical encoding?
ord
To handle issues with different path formats across different operating systems, this module should be used to generate paths: ______.path
os
What is it called when a program puts data somewhere, such as the screen or a file?
output
What version of Python is used in this class?
python 3
________ can be used when a programmer may want a program to stop executing if an unfinished function is called
raise NotImplementedError
Which function generates a sequence of numbers?
range ()
To generate every integer from 4 down to -3, which range function should be used? Sequence: 4 3 2 1 0 -1 -2 -3
range(4, -4, -1)
In an open statement, if only the first argument (path to file) is specified, Python opens the file in ______ mode
read
When using string-formatting syntax, each pair of braces {} is known as a ___
replacement field
Which of the below is most similar to Floating Point representation?
scientific notation
The process of searching for a name in the available namespaces is called _________
scope resolution
What is an example of an output device?
screen
String, list, and tuple are ______ type of data
sequence
Which of the following is not a property associated with variables in Python?
status
What data type is the variable a in the following statement? a = '10'
string
What type of value is returned by the input command?
string
What is text enclosed in quotes known as?
string literal
What kind of error is caused when you violate the programming language's rules?
syntax error
To access command-line arguments passed to your script, which module should you use?
sys.argv
Given my_str = 'Carson Wentz', evaluate the expression: my_str is 'Carson Wentz' T or F?
true
Incremental programming may help reduce the number of errors in a program.
true
What is the value of result after the following code is run? a = False b = False c = True result = not b or not a and b
true
What is the value of result after the following code is run? a = True b = True c = False result = not c or a or c
true
The final number of As, Bs, Cs, Ds, and Fs in the class can best be represented using
tuple
What error will be raised by the following code? q = ['10', '20', '30', 'Yellow'] for e in q : print(e) print(float(e) * 10)
value error: invalid literal
To go through the files and subdirectories within a specific directory, which method from the os module is useful?
walk ()
Which loop should be used when iterating until the values of a and b are not equal.
while loop
The split() string method uses __ as the default separator.
whitespaces
What string slicing operation can be used to get every third character of a string x?
x[::3]