Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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 :)

  1. Given the for loop header below, how many times will the looprepeat?

    for total in range(5, 10):

    1. 5 times

    2. 6 times

    3. 2 times

    4. 10 times

  2. 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.

    1. for counter in range(10):

      sum = sum + counter

    2. for counter in range(1, 10):

      sum = sum + counter

    3. for counter in range(1, 11):

      sum = sum + counter

    4. for counter in range(1, 10, 1):

      sum = sum + counter

  3. 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)

    1. break

    2. continue

    3. pass

    4. None of the above

  4. 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.

    1. True
    2. False
  5. Question 5

    Given the while loop below, how many times will the loop bodyexecute?

    counter = 10

    while (counter < 10):

    counter = counter - 1

    1. 0

    2. 1

    3. 9

    4. 10

  6. 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.

    1. True
    2. False
  7. Question 7

    5 Points

    Given the for loop header below, how many times will the looprepeat?

    for counter in range(10, 0, -3):

    1. 10

    2. 4

    3. 0

    4. The loop is infinite.

  8. Question 8

    What is the output of the following while loop?

    counter = 1

    while (counter < 10):

    print(counter)

    1. Nothing. The loop never begins.

    2. All the integer values from 1 to 9

    3. All the integer values from 1 to 10

    4. The loop is infinite.

  9. Question 9

    What is the output of the while loop given below?

    counter = 5

    while(counter != 0):

    print(counter)

    counter = counter - 2

    1. All of the integer values from 5 to 1

    2. All of the odd numbers from 5 to 1

    3. The loop is infinite.

    4. Nothing. The loop never begins.

  10. 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.

    1. True
    2. False

ARRAYS

  1. Which of the following statements are true about lists inPython? Select all that apply

    1. All elements must be of the same data type.

    2. [1, 2, 3] and [3, 2, 1] are functionally the same list.

    3. An element may appear more than once in a given list.

    4. A list may contain elements of another collection type, such asa list of lists.

  2. Question 2

    5 Points

    What is the output of the following code?

    numList = [10, 20, 30, 40, 50]

    print( numList[1] )

    1. 10

    2. 20

    3. [10, 20, 30, 40, 50]

    4. Syntax error

  3. 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

    1. [5, 10, 15, 20, 25]

    2. [5, 5, 10, 10, 15]

    3. [5, 5, 5, 5, 5]

    4. [0, 5, 10, 10, 25]

  4. 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)

    1. ['c', 'b', 'a', 'd']

      ['c', 'b', 'a', 'd', 'a']

    2. ['c', 'b', 'a', 'd']

      ['c', 'b', 'a', 'd']

    3. ['c', 'b', 'a', 'd']

      ['c', 'b', 'a', 'a']

    4. ['c', 'b', 'a']

      ['c', 'b', 'a']

  5. 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])

    1. [25, 30, 35, 40]

    2. [25, 30, 35, 40, 45]

    3. [30, 35, 40, 45]

    4. [30, 35, 40, 45, 50]

  6. 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])

    1. [45, 35, 25, 15]

    2. [45, 35, 25, 15, 5]

    3. [40, 30, 20, 10]

    4. Syntax error

  7. Question 7

    5 Points

    Which of the following collection types is ordered,unchangeable, and allows duplicate values?

    1. list

    2. tuple

    3. set

    4. dictionary

  8. Question 8

    5 Points

    Which of Python's collection types can be used to storekey:value pairs?

    1. lists

    2. tuples

    3. sets

    4. dictionaries

  9. Question 9

    5 Points

    Which of the following statements are true about sets in Python?Select all the apply.

    1. All elements must be of the same data type.

    2. {1, 2, 3} and {3, 2, 1} are fundamentally the same set.

    3. Each element may only appear once in a set.

    4. The values of a set can be modified after creation.

  10. Question 10

    5 Points

    Of Python's collection types, sets are the most like traditionalarray data structures in other languages.

    1. True
    2. 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 ... 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

Recommended Textbook for

Discovering Advanced Algebra An Investigative Approach

Authors: Jerald Murdock, Ellen Kamischke, Eric Kamischke

1st edition

1559539844, 978-1604400069, 1604400064, 978-1559539845

More Books

Students also viewed these Programming questions

Question

Find the equation of the parabola at right? 0.-15 2-2.5) +4+4

Answered: 1 week ago