Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

PYTHON multiple choice questions 1a) Given the following list, what value is at index 5? values = [1, 2, 3, 4, 5, 6, 7, 8,

PYTHON multiple choice questions

1a) Given the following list, what value is at index 5?

 values = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] 
5
6
7
4

1b) Consider the following line of code:

somelist = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"] 

Which one of the following options is a valid line of code for displaying the element at the twenty-second position in the list?

somelist(21) 
somelist[21] 
print(somelist(21)) 
print(somelist[21]) 

1c) Which statement correctly identifies the error in this code snippet?

scores = [80, 85, 60.5, 95, 70] print(scores[5]) 

DataTypeError: cannot mix integer and floating point numbers

There is no error. The code runs and prints 70.

NameError: name 'scores' is not defined 

IndexError: list index out of range

1d) What is the difference between a list and a string?

lists are sequences but strings are not and therefore you cannot access a string element using []

lists are immutable, but strings can be changed

lists can hold values of any type, whereas strings are only sequences of characters

elements in a list can be accessed using an integer as the index value, but strings can use any numeric data type for the index

1e) Given a list values that contains the first ten prime numbers, which statement prints the index and value of each element in the list?

for i in range(11): print(i, values[i]) 
for i in range(10): print(i, values[i]) 
for i in range(1, 10): print(i, values[i]) 
for i in range(1, 11): print(i, values[i]) 

1f) Consider the following code snippet. What will be stored in the list prices after this code executes?

prices = [10.00, 15.50, 13.50, 20.15] for i in range(len(prices)): prices[i] = prices[i] * 1.06 
[10.00, 15.50, 13.50, 20.15] 
[10.60, 16.43, 14.31, 21.36] 
[1.06, 1.06, 1.06, 1.06] 
[0.0, 0.0, 0.0, 0.0] 

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

25.0 m C B A 52.0 m 65.0 m

Answered: 1 week ago