Frequently Tested Exam Questions With
Verified Multiple Choice and Conceptual
Actual 100% Correct Detailed Answers
Guaranteed Pass!!Current Update!!
1) Assume the following list has been created:
scores = [[75,100,82,76], [85,98,89,99], [75,82,85,5]]
Write an indexing expression that gets the element from scores whose value is
100. - ANSWER scores[0][1]
2. scores = [[75,100,82,76], [85,98,89,99], [75,82,85,5]]
How many elements does scores contain? (The result of len(scores)). - ANSWER
3 that are lists.
3. Assume that the following code has been evaluated: nums = [1,1,2,3,5,8,13].
What is the result of nums[1:5]? - ANSWER [1,2,3,5]
nums = [1,1,2,3,5,8,13].
4. What is the result of nums[5:10]? - ANSWER [8,13]
nums = [1,1,2,3,5,8,13].
5. What is the result of nums [3:-1]? - ANSWER [3,5,8
,Given the following code: nums = [0,25,50,75,100]:
6. The result of evaluating nums[0:5:2] is [25, 75]. - ANSWER False [0,50,100].
Indexs 0 through 5 stepping 2.
nums = [0,25,50,75,100]
7. The result of evaluating nums[0:-1:3] is [0, 75]. - ANSWER True. Index 0
going backwards stepping 3.
8. Consider the following program:
nums = [10, 20, 30, 40, 50]
9. for pos, value in enumerate(nums):
tmp = value / 2
if (tmp % 2) == 0:
nums[pos] = tmp
What's the final value of nums[1]? - ANSWER 10
10. Iterating over a list and deleting elements from the original list might cause a
logical program error. - ANSWER True
11. A programmer can iterate over a copy of a list to safely make changes to that
list. - ANSWER True
,12. Twice the value of each element in the list variable x. - ANSWER [i*2 for i
in x]
13. The absolute value of each element in x. Use the abs() function to find the
absolute value of a number. - ANSWER [abs(i) for i in x]
14. The largest square root of any element in x. Use math.sqrt() to calculate the
square root. - ANSWER max([math.sqrt(i) for i in x])
15. Write a list comprehension that contains elements with the desired values.
Use the name 'i' as the loop variable. Use parentheses around the expression or
condition as necessary.
Only negative values from the list x: - ANSWER [i for i in x if i < 0]
16. Only negative odd values from the list x. - ANSWER [(i) for i in x if ((i < 0)
and (i % 2 == 1))]
17. Dictionary entries can be modified in-place - a new dictionary does not need
to be created every time an element is added, changed, or removed. True or False
- ANSWER True
18. The variable my_dict created with the following code contains two keys, 'Bob'
and 'A+'. my_dict = dict(name='Bob', grade='A+'). True or False - ANSWER
False
, Determine the output of each code segment. If the code produces an error, type
None. Assume that my_dict has the following entries:
my_dict = dict(bananas=1.59, fries=2.39, burger=3.50, sandwich=2.99).
my_dict.update(dict(soda=1.49, burger=3.69))
burger_price = my_dict.get('burger', 0)
print(burger_price) - ANSWER Output: 3.69
19. Determine the output of each code segment. If the code produces an error,
type None. Assume that my_dict has the following entries:
my_dict = dict(bananas=1.59, fries=2.39, burger=3.50, sandwich=2.99)
my_dict['burger'] = my_dict['sandwich']
val = my_dict.pop('sandwich')
print(my_dict['burger']) - ANSWER Output: 2.99
Print each key in the dictionary my_dict. - ANSWER for key in my_dict
print(key)
Change all negative values in my_dict to 0. - ANSWER for key, value in
my_dict.items()
if value < 0: