Ch. 6 loops python programming

0.0(0)
Studied by 0 people
call kaiCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/18

encourage image

There's no tags or description

Looks like no tags are added yet.

Last updated 4:43 AM on 5/18/26
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai

No analytics yet

Send a link to your students to track their progress

19 Terms

1
New cards

loop

A loop is a program construct that repeatedly executes the loop's statements (known as the loop body) while the loop's expression is true; when the expression is false, execution proceeds past the loop

2
New cards

iteration

Each time through a loop's statements is called an iteration.

3
New cards

While loop

A while loop runs a block of code repeatedly as long as the while loop's condition is True.

4
New cards

sentinel value

A sentinel value is a value that causes a loop to end.

5
New cards

Infinite loop

An infinite loop is a loop that never stops running because the loop's condition is always True.

6
New cards

randint() function

provides a new random number each time the function is called

7
New cards

doc string

a multi-line string literal delimited at the beginning and end by triple quotes, which can be either single (') or double (") quotes.

8
New cards

for loop statement

iterates over each element in a container one at a time, assigning a variable to the next element to use in the loop body.

9
New cards

reversed () function

A for loop may also iterate backward over a sequence, starting at the last element and ending with the first element

10
New cards

range() function

generates a sequence of integers between a starting integer that is included in the range, an ending integer that is not included in the range, and an integer step value. The sequence is generated by starting at the start integer and incrementing by the step value until the ending integer is reached or surpassed.

11
New cards

for i in range(4):
print(i, end=" ")

0 1 2 3

12
New cards

Positive integer months_upp is read from input, representing the months lapsed since the beginning of the year. Complete the for loop as follows:

  • Use curr_month as the loop variable.

  • Iterate through the decreasing sequence of all the integers from months_upp down to 1, both inclusive.

months_upp = int(input())

print("Months passed:", end=" ")

for curr_month in range(months_upp, 0, -1):

print(curr_month, end=" ")

print()

13
New cards

Integers begin_item and end_item are read from input, representing the items in an assembly line, with begin_item less than end_item. Integer items_passed is initialized with 0. For every fourth item between begin_item and end_item, both inclusive:

  • Output "Sampling item: " followed by the item's value.

  • Increment items_passed.

begin_item = int(input())

end_item = int(input())

items_passed = 0

for item in range(begin_item, end_item +1, 4):

print("Sampling item:", item)

items_passed += 1

print(f"Total items passed: {items_passed}")

14
New cards

nested loop

a loop that appears as part of the body of another loop. The nested loops are commonly referred to as the outer loop and inner loop.

15
New cards

incremental programming

by starting with a simple version of the program, and growing the program little by little into a complete version

16
New cards

break statement

cases the loop to exit immediately

17
New cards

continue statement

A continue statement in a loop causes an immediate jump to the while or for loop header statement.

18
New cards

loop else construct

executes if the loop completes normally.

19
New cards

enumerate() function

retrieves both the index and corresponding element value at the same time, providing a cleaner and more readable solution