Hack 1

Iteration: Part of an Algorithm that repeats itself until a certain condition is met

  1. Start
  2. the number of petals on a flower is 8
  3. pick off one petal, and number of petals goes down by one
  4. How many petals are left?
  5. repeat step three until number of petals is zero
  6. Finish
numPetals = 8
while (numPetals > 0):
    numPetals -= 1
    print(numPetals)
    if numPetals == 0:
        print("No More Petals")
# EXTRA BONUS
    if numPetals % 2 == 0:
        print("I am smart")
    if numPetals % 2 == 1:
        print("I am dumb")
7
I am dumb
6
I am smart
5
I am dumb
4
I am smart
3
I am dumb
2
I am smart
1
I am dumb
0
No More Petals
I am smart

Iteration Statement: loop repeats zero or more times, until disturbed (loop is stopped)

i=3
while i<=81:
	print(i)
	i=i+13
3
16
29
42
55
68
81

Hack 2

colors = ["red", "orange", "yellow", "green", "blue", "purple"]
for i in colors:
    if i == "green":
        break
    print(i)
# it will stop printing after yellow, prints until green
red
orange
yellow
nums = ['38', '45', '67', '83', '78']
least = min(nums)
# minimum
print(min(nums))
# print minimum
for i in nums:
# loop to check if there are any smaller numbers
    if i < (min(nums)):
#if there are any numbers that are even smaller than the one before, it will print the new one, but there isn't.
        print(i)
38

Reference sheet notes (4)

  • Append adds something to the list (at the end of the list)
  • Insert adds something to the list (anywhere in the list)
  • Removes whatever is at the index you put
  • you can assign the values of a list to another list