Important Vocab/Notes
- For Loop - FOR LOOP repeats a function for a set number of times; I is the number of times repeated
- While Loop - The while loop is used to repeat a section of code an unknown number of times until a specific condition is met
- Initialization - What sets the counter variable to a starting value. For example (var i = 0) represents an initial value of 0.
- Condition - Allows the computer to know whether or not to keep repeating the loop.
- Increment/decrement - Modifies the counter variable after each repetition.
- Append, remove, pop - Various methods, append adds an element to the end, remove removes at an index, and pop removes the last item.
- Iterative statements are also called loops, and they repeat themselves over and over until the condition for stopping is met
list = [1, 2, 3, 4, 5] # Print this list in reverse order
list.reverse()
print('Reversed List:', list)
list = [9, 8, 4, 3, 5, 2, 6, 7, 1, 0] # Sort this
list.sort()
print('Sorted List:', list)
list = [9, 8, 4, 3, 5, 2, 6, 7, 1, 0]
print(f"listay before sort: {list}")
def insertion_sort(list):
for index in range(1,len(list)): # repeats through length of the listay
value = list[index]
i = index - 1
while i >= 0:
if value < list[i]:
list[i+1] = list[i] # shift number in slot i to the right
list[i] = value # shift value left into slot i
i = i - 1
else:
break
IS = insertion_sort(list)
print(f"listay after sort: {list}")
I got question 8 wrong (image wont load)
- I selected a because I thought a certain about of time met until a conditon is met
- I am not sure why I selecetd b because it was not very close to the answer and did not make much sense
- I selected c after because I realized it was saying the code repeats until a conditon is met, which is a While Loop