Complete Questions and Correct
Answers | Verified Answers | Latest
Exam
What's the output of the following code?
def find(all, target):
left = 0
right = len(all) - 1
while left <= right:
mid = (left + right) // 2
print(mid, all[mid])
if all[mid] == target:
return mid
elif all[mid] > target:
right = mid - 1
else:
left = mid + 1
return -1
def main():
all = [1, 2, 5, 8, 11, 15, 19]
print(find(all, 6))
main() ---------CORRECT ANSWER-----------------3 8
,12
25
-1
What's the output of the following code?
def find(all, target):
left = 0
right = len(all) - 1
while left <= right:
mid = (left + right) // 2
print(mid, all[mid])
if all[mid] == target:
return mid
elif all[mid] > target:
right = mid - 1
else:
left = mid + 1
return -1
def main():
all = [1, 2, 5, 8, 11, 15, 19]
print(find(all, 5))
main() ---------CORRECT ANSWER-----------------3 8
12
,25
2
Given the following statement in a code
from random import *
which of the following is a correct statement to shuffle list list1? ---------CORRECT
ANSWER-----------------shuffle(list1)
What is the output of the following code?
aList = [1, 2, 3, 4]
aList.reverse()
print(aList) ---------CORRECT ANSWER-----------------[4, 3, 2, 1]
What is the output when the following code segment is executed?
firstList = [10, 31, 85, 96]
secondList = firstList
secondList[1] = 400
print(secondList)
print(firstList == secondList) ---------CORRECT ANSWER-----------------[10, 400, 85,
96] True
, Suppose list1 is [13, 18, 59, 21, 75, 44], what are the elements of list1 after
executing list1.pop()? ---------CORRECT ANSWER-----------------[13, 18, 59, 21, 75]
Suppose that list1 is [99,16, 85, 43], What is the result of list1[:-1]? ---------
CORRECT ANSWER-----------------[99,16, 85]
Given a list1 with the following value:
list1 = [ [9, 7, 4], [0, 99, 8], [74, 33, 89]]
which of the following expression has the value of 99. ---------CORRECT ANSWER---
--------------list1[1][1]
What is the output of the following code?
all = [4, 3, 2, 8, 7, 5, 3, 1, 3]
print(all.count(3))
print(all.count(9)) ---------CORRECT ANSWER-----------------3
0
What's the output of the following program?
t1 = (1, 2)
t2 = (3, 4)
print(t1 + t2) ---------CORRECT ANSWER-----------------(1, 2, 3, 4)