Unit 3 Sections 8 and 10
During this lesson sections 8 and 10 hacks will be completed
Iteration
- repeating portion of an algorithm, repeats a specified number of times or until a given condition is met
import random
i = 10
while (i < 100):
print('you are less than 100 years old')
i = i + 30
if (i > 100):
break
nums = [44, 55, 33, 66, 77, 88, 99, 100]
for n in nums:
if n % 2 == 0:
print('This did not affect you at all')
Iteration Statement
- Iteration statements cause statements to be executed zero or more times, subject to some loop-termination criteria
for i in range(100,105):
i = i + 98
print(i)
else:
print('this is how you count from 198 to 202')
a = [3,16,29,42,55,68,81]
c = 2
while (c) > 1:
c +=1
print(a);
c == 3
break
nums = ["30", "40", "50", "15", "20", "433"]
minimum = min(nums)
print(minimum, "This is the lowest number")
# Part 2
low = (nums[0])
for i in range(len(nums)):
if (nums[i]) < low:
low = nums[i]
print("the lowest number in nums is:", low)