Programming Homework Help

Programming Homework Help. University of Maryland Global Campus Collection of Numeric Values Questions

Question 1 (10 points)

undefined

Which of the following is the correct output from the following program?

sequence = [1, 4, 7, 10, 13]
for i in range(len(sequence)):
if i > 2:
sequence[i] = sequence[i] – sequence[i-2]
print(sequence)

Question 1 options:

[1, 4, 7, 10, 6]

[1, 4, 7, 6, 6]

[1, 4, 6, 6, 6]

[1, 4, 7, 10, 13]

Question 2 (10 points)

undefined

Which of the following for loops will compute the sum of all the elements in the array numbers, assuming numbers has already been assigned a collection of numeric values?

Question 2 options:

sum = 0
for i in range(len(numbers)):
sum = numbers[i]

sum = 0
for i in range(numbers):
sum = numbers[i]

sum = 0
for i in range(len(numbers)):
sum = sum + i

sum = 0
for i in range(len(numbers)):
sum = sum + numbers[i]

Question 3 (10 points)

undefined

Which of the following is the correct output from the following sequence of statements?

sequence = [0, 1, 1, 2, 3, 5, 8]
sequence[-3] = 0
print(sequence[5])

Question 3 options:

5

0

3

It generates an IndexError

Question 4 (10 points)

undefined

Which of the following is the correct output from this sequence of statements?

letters = [‘a’, ‘b’, [‘c’, ‘d’, [‘e’, ‘f’]], ‘g’]
print(len(letters[2]))

Question 4 options:

6

4

3

7

Question 5 (10 points)

undefined

Which of the following is the correct output from this sequence of statements?

digits = [‘1’, ‘2’, ‘3’, ‘4’, ‘5’, ‘6’]
digits.remove(‘2’)
third = digits.pop(3)
print(digits)

Question 5 options:

[‘2’, ‘4’, ‘5’, ‘6’]

[‘1’, ‘3’, ‘4’, ‘6’]

[‘1’, ‘2’, ‘5’, ‘6’]

[‘1’, ‘2’, ‘4’, ‘6’]

Question 6 (10 points)

undefined

Which of the following is the correct output from this sequence of statements?

array1 = [1, 2, 3]
array2 = [2, 3]
print(array1 + array2 * 2)

Question 6 options:

[1, 2, 3, 2, 3, 2, 3]

[1, 2, 3]

[1, 2, 3, 2, 3, 1, 2, 3, 2, 3]

[1, 2, 3, 2, 3]

Question 7 (10 points)

undefined

Which of the following is the correct output from this sequence of statements?

cubes = [1, 8, 27, 64, 125, 216]
cubes[3:5] = [1, 2]
print(cubes[2:6])

Question 7 options:

[1, 2, 216]

[8, 27, 1, 2]

[8, 1, 2, 125]

[27, 1, 2, 216]

Question 8 (10 points)

undefined

Which of the following programs will output None?

Question 8 options:

values = [7, 10, 13, 16]
values.extend([1, 4])
values.sort()
print(values)

values = [7, 10, 13, 16]
values.append(1)
values.append(4)
values.sort()
print(values)

values = [7, 10, 13, 16]
values.sort()
values.extend([1, 4])
print(values)

values = [7, 10, 13, 16]
values.append(1)
values.append(4)
print(values.sort())

Question 9 (10 points)

undefined

Which of the following is the correct output from this sequence of statements?

numbers = [18, 27, 42, 13, 21, 8, 11]
print(sum(numbers) / len(numbers))

Question 9 options:

42.0

20.0

7.0

8.0

Question 10 (10 points)

undefined

Which of the following is the correct output from this sequence of statements?

numbers = [1, 2, 3]
numbers.append(2)
numbers.sort()
print(numbers)

Question 10 options:

[1, 2, 3, 2]

[1, 2, 2, 3]

None

[1, 2, 3]

Programming Homework Help