Conditional Statements & Loops: While Loops in Python

¡Supera tus tareas y exámenes ahora con Quizwiz!

What is the output of the following code? my_list = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'] i = 0 while i < len(my_list): print(my_list[i]) i += 3

a d g

What is the output of the following code? my_list = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'] vowels = ['a', 'e', 'i', 'o', 'u'] i = 0 while i < len(my_list): if(my_list[i] in vowels): i += 1 continue print(my_list[i]) i += 2

b d f h

Which TWO of the following statements about while and for loops are TRUE?

for loops iterate over a sequence without the user needing to maintain an index to that sequence while loops continue to loop while the condition is True and end when the condition evaluates to False

What is the number of iterations the following while loop will perform before terminating? x = 4 while x < 4+6: print(x) x += 1

6

Consider the code below: inventory = [] item = "" while item != "quit": item = input("Enter an item to add to the inventory: ") print("Adding item:", item) inventory.append(item) What is the number of iterations of the while loop?

Depends on when the user types "quit"

Which of the following statements about the use of break statements in a while loop are true?

If break is invoked, the else block associated with the while loop is not executed

What is the number of iterations the following while loop will perform before terminating? x = 4 while x < 10: print(x+1)

Infinite

What is the output of this while loop? x = 8 while x < 10: print(x) x += 1

Syntax error

What is the effect of the pass statement within a nested while loop being invoked?

There is no effect on code execution


Conjuntos de estudio relacionados

Physiological Psych. Module 6.1 Quiz

View Set

medsurge prep u osteoarthritis nclex questions

View Set

Principles of Mgmt Chapter 2 Study Guide

View Set

Chapter 3: Prenatal Development, Birth, and the Newborn Baby

View Set

La Gran Aventura De Alejandro In English

View Set