3.8 and 3.10 Iteration/Lists
HW 4
Notes
Section Objectives:
- Express an algorithm that uses iteration without using a programming language
- Determine the result or side effect of iteration statements
- Write iteration statements
Vocab
-
Iteration: a repeating portion of an algorithm, repeats a specified number of times or until a given condition is met
-
Iteration Statements: change the sequential flow of control by repeating a set of statements zero or more times, until a stopping condition is met
-
Repeat Until: if the condition evaluates to true initially, the loop body is not executed at all, due to the condition being checked before the loop
-
Complete Traversal: All elements in a list are assessed
-
Partial Traversal: Only a given portion of elements are assessed
-
Iterative Traversal: When loops are used to iterate through a list and to access each single element at a time.
Notes
- Iteration is part of an agrothim
- Keeps looping until problem is finshed
- range excludes that last value
- insert( ) allows a value to be inserted into a list at index i
- append( ) allows a value to be added at the end of a list
- remove( ) allows an element at index i to be deleted from a list
- length( ) returns the number of elements currently in a specific list
water = ["whale", "trout", "shark", "bass", "nemo"]
for fi in water:
if i == "nemo":
print("nemo is here")
break
else:
print(i + " is not nemo")
for i in reversed(range(1,11)):
print(i)
numbers = 0
n = 1
while numbers < 80:
numbers = 3+(n-1)*13
n = n + 1
print(numbers)
nums = [10, 15, 20, 25, 30, 35]
mnums = min(nums)
for i in nums:
if i > mnums:
mnums = mnums + 5
else:
mnums = mnums + 5
print(mnums)