HACKS Unit 3 Section 8

Hacks Unit 3 Section 3.8.1

  • Define an Iteration Portion of code segments that repeat until the requirement is met
  • Make your own example of an iteration with at least 4 steps and a stopping condition(Similar to mine that I did)
    1. I have n homeworks to do
    2. Start and finish homework assignment
    3. Move onto next homework assignment
    4. Repeat steps 2-3 until there is no more homework
  • Program a simple iteration.
fruit = ["apple", "orange", "strawberry", "pear"]
i = 0
for x in fruit:
    print(fruit[i])
    i += 1
apple
orange
strawberry
pear

Hacks Unit 3 Section 3.8.2

  • What is an iteration statement, in your own words? They change the order or course that the code is executed by repeating a section of code until the condition is met
  • Create a descending list of numbers using for loop
for x in range(10, -1, -1):
    print(x)
10
9
8
7
6
5
4
3
2
1
0
  • Using while loop, make a list of numbers which will form an output of 3,16,29,42,55,68,81
for x in range(3, 94, 13):
    print(x)
3
16
29
42
55
68
81

HACKS Unit 3 Section 10

  • Find the lowest value in a list (Luna Iwazaki)
    • Use the list made below
    • Make a variable to hold the minimum and set it to potential minimum value
    • Loop
    • Check each element to see if it is less than the minimum variable
    • If the element is less than the minimum variable, update the minimum
    • After all the elements of the list have been checked, display the minimum value
nums = ["10", "15", "20", "25", "30", "35"]
potentialMin = int(nums.pop())
while len(nums) != 0:
    newNum = int(nums.pop())
    if newNum < potentialMin:
        potentialMin = newNum
print(potentialMin, "is the minimum value.")
10 is the minimum value.
  • Lists Quiz (Ethan Tran) Take a screenshot of your score on put it on your review ticket!