Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

How many times will the body of the loop execute? my_list = [-6, 2, -8, 1, -12, 15, -7] val = Get the first my_list

How many times will the body of the loop execute?

my_list = [-6, 2, -8, 1, -12, 15, -7] val = Get the first my_list value While val is negative: put "Negative number!" to output val = Get the next my_list value Put "Done" to output

a.1

b.2

c.3

d.4

e.5

f.0

In which of the following cases is a while loop more appropriate than a for loop?

a.Iterate 10 times

b.Iterate until a user enters the letter 'q'

c.Printing out numbers from a given range

d.Incrementing each element in a list by 5

Question 3

How many times does the following loop iterate?

i starts at 4 While i < 10 Print i Increment i by 2

Answer:

What is the output of the last print statement?

def math(x, y):

z = x + y

print(z)

math(5, 7)

print(z)

a.12

b.5

c.None

d.Error

e.7

Question 5

Given my_lst=[1,2,3,4,5,6] what is the output of printing any(my_lst)?

a.False

b.True

What is the output of the following list operation

aList = [10, 20, 30, 40, 50, 60, 70, 80] print(aList[2:5]) print(aList[:4])

a.

[30, 40, 50, 60, 70, 80]

b.

[40, 50, 60, 70, 80]

c.

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

d.

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

Question 7

True or False. When using keyword arguments, the argument list needs to follow a specific ordering.

a.True

b.False

Question 8

Given that sentence="Hey, my name is Jonathan!" what is the output of print(sentence.split(","))

a.['Hey', ' my name is Jonathan' , '!']

b.['Hey', ' my name is Jonathan!']

c.['Hey', 'my', 'name', 'is', 'Jonathan!']

d.['Hey,' , ' my name is Jonathan!']

Question 9

What is the output of this code?

def change(lst):

lst[1]=10

lst=[1,2,3]

new_lst=lst

change(new_lst)

print(lst)

a.[1, 10, 3]

b.[1, 2, 3, 10, 2, 3]

c.[10, 2, 3]

d.[1, 2, 3]

Question 10

Given my_lst=[0,1,2,3,4,5,6] what is the output of printing all(my_lst)?

a.True

b.False

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

Recommended Textbook for

Financial management theory and practice

Authors: Eugene F. Brigham and Michael C. Ehrhardt

12th Edition

978-0030243998, 30243998, 324422695, 978-0324422696

Students also viewed these Programming questions

Question

Implementing marketing public relations

Answered: 1 week ago