Search Header Logo

SAQ 4.1

Authored by Parker Gaston

Other

University

SAQ 4.1
AI

AI Actions

Add similar questions

Adjust reading levels

Convert to real-world scenario

Translate activity

More...

    Content View

    Student View

17 questions

Show all answers

1.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

Using a for loop, we can iterate through the items of a Python list in either a "by item" or a "by index" manner.

True

False

2.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

This function is supposed to sum all of the elements in a list of numbers. Which of the following should replace the comment line?

def sumList(myList):

acc = 0

# what goes here?

acc = acc + myList[i]

return acc

 

for i in range(len(myList)):

for acc in myList:

 

for myList:

 

for x in myList:

3.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

Assuming the parameter myList is a list of integers between zero and 100, what does this function return?

def foo(myList):

  x = -1

  for y in myList:

    if y > x:

      x = y

 

  return x

 

The second largest value in myList

 

The smallest value in myList

 

The second smallest value in myList

 

The largest value in myList

4.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

What is the output of this code?

myList = [-1, 4, 5, -3, 8, 4, 1, 0, -3, 0]

acc = 0

for i in myList:

  if i > 0:

    acc = acc + i

acc

 

-7

22

 

7

 

45

5.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

What is output by the following code?

changeList = [1, 2, "buckle my shoe", 3, 4, "shut the door"]

changeList[2] = "the sky is blue"

changeList

 

'the sky is blue'

[1, 2, "the sky is blue", 3, 4, "shut the door"]

 

[1, 'the sky is blue', "buckle my shoe", 3, 4, 'shut the door']

 

TypeError:object does not support item assignment

6.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

Python provides the _________ function to create a list from a range or string.

list

append

insert

 

[ ]

7.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

The __________ list method removes and returns the last item in a list.

remove

reverse

count

pop

Access all questions and much more by creating a free account

Create resources

Host any resource

Get auto-graded reports

Google

Continue with Google

Email

Continue with Email

Classlink

Continue with Classlink

Clever

Continue with Clever

or continue with

Microsoft

Microsoft

Apple

Apple

Others

Others

Already have an account?