Question
Python Multiple Choice LOOP and ARRAY No need for explanation. I always upvote if correct.Thank you in advance, cheers :) Given the for loop header
Python Multiple Choice LOOP and ARRAY
No need for explanation. I always upvote if correct.Thank you in advance, cheers :)
Given the for loop header below, how many times will the looprepeat?
for total in range(5, 10):
5 times
6 times
2 times
10 times
- Question 2
Which of the following loops will calculate the sum of all ofthe numbers from 1 to 10, including 1 and 10. You can assume thatsum has been initialized to a starting value of0.
for counter in range(10):
sum = sum + counter
for counter in range(1, 10):
sum = sum + counter
for counter in range(1, 11):
sum = sum + counter
for counter in range(1, 10, 1):
sum = sum + counter
- Question 3
Which statement can be used to skip the remainder of the loopbody for a single iteration, without exiting the entire loop (thatis, the loop may repeat again if the condition is still true)
break
continue
pass
None of the above
- Question 4
If the loop control variable of a while loop is not modifiedwithin the body of the loop, the loop will default to incrementingthe value by +1 on each iteration.
- True
- False
- Question 5
Given the while loop below, how many times will the loop bodyexecute?
counter = 10
while (counter < 10):
counter = counter - 1
0
1
9
10
- Question 6
The break statement can be used to provide an alternative exitcondition for a loop, as it terminates the loop immediately withoutreturning to evaluate the condition.
- True
- False
- Question 7
5 Points
Given the for loop header below, how many times will the looprepeat?
for counter in range(10, 0, -3):
10
4
0
The loop is infinite.
- Question 8
What is the output of the following while loop?
counter = 1
while (counter < 10):
print(counter)
Nothing. The loop never begins.
All the integer values from 1 to 9
All the integer values from 1 to 10
The loop is infinite.
- Question 9
What is the output of the while loop given below?
counter = 5
while(counter != 0):
print(counter)
counter = counter - 2
All of the integer values from 5 to 1
All of the odd numbers from 5 to 1
The loop is infinite.
Nothing. The loop never begins.
- Question 10
Both while loops and for loops can be modified with the additionof an else statement, that executes automatically when the loopends due to the condition evaluating to False.
- True
- False
ARRAYS
Which of the following statements are true about lists inPython? Select all that apply
All elements must be of the same data type.
[1, 2, 3] and [3, 2, 1] are functionally the same list.
An element may appear more than once in a given list.
A list may contain elements of another collection type, such asa list of lists.
- Question 2
5 Points
What is the output of the following code?
numList = [10, 20, 30, 40, 50]
print( numList[1] )
10
20
[10, 20, 30, 40, 50]
Syntax error
- Question 3
5 Points
What are the contents of the list after the following code hasexecuted?
numList = [5, 10, 15, 20, 25]
counter = 1
while(counter < (len(numList))):
numList[counter] = numList[counter] -numList[counter-1]
counter = counter + 1
[5, 10, 15, 20, 25]
[5, 5, 10, 10, 15]
[5, 5, 5, 5, 5]
[0, 5, 10, 10, 25]
- Question 4
5 Points
What is the output of the following code?
aList = ['c', 'b', 'a']
aList.append('d')
print(aList)
aList.append('a')
print(aList)
['c', 'b', 'a', 'd']
['c', 'b', 'a', 'd', 'a']
['c', 'b', 'a', 'd']
['c', 'b', 'a', 'd']
['c', 'b', 'a', 'd']
['c', 'b', 'a', 'a']
['c', 'b', 'a']
['c', 'b', 'a']
- Question 5
5 Points
What is the output of the following code?
aList = [5, 10, 15, 20, 25, 30, 35, 40, 45,50]
print(aList[5:9])
[25, 30, 35, 40]
[25, 30, 35, 40, 45]
[30, 35, 40, 45]
[30, 35, 40, 45, 50]
- Question 6
5 Points
What is the output of the following code?
aList = [5, 10, 15, 20, 25, 30, 35, 40, 45,50]
print(aList[8:0:-2])
[45, 35, 25, 15]
[45, 35, 25, 15, 5]
[40, 30, 20, 10]
Syntax error
- Question 7
5 Points
Which of the following collection types is ordered,unchangeable, and allows duplicate values?
list
tuple
set
dictionary
- Question 8
5 Points
Which of Python's collection types can be used to storekey:value pairs?
lists
tuples
sets
dictionaries
- Question 9
5 Points
Which of the following statements are true about sets in Python?Select all the apply.
All elements must be of the same data type.
{1, 2, 3} and {3, 2, 1} are fundamentally the same set.
Each element may only appear once in a set.
The values of a set can be modified after creation.
- Question 10
5 Points
Of Python's collection types, sets are the most like traditionalarray data structures in other languages.
- True
- False
Step by Step Solution
3.31 Rating (148 Votes )
There are 3 Steps involved in it
Step: 1
The detailed answer for the above question is provided below Answer 1 6 times 2 for counter in range1 11 sum sum counter 3 continue 4 False 5 0 6 True ...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started