CS106 Summer 2026 Michael Eckmann Lab 03 July 07, 2026 ================== Purpose: understanding various examples of while and for loops, some with breaks understanding lists, elements and indices learning that list elements can change (lists are mutable) learning that strings cannot change (strings are immutable) =================== 1. Type the following code in to the shell part of idle3, one line at a time: some_list = [100,320,240,-87, 65] # Predict what will output in each of these individually and then type them in to see if you were correct: print(some_list[0]) print(some_list[-1]) print(some_list[4]) print(len(some_list)) some_list.append(7) print(some_list) some_list.remove(240) print(some_list) some_list.remove(3) print(some_list) some_list.reverse() word = 'hello' result = word.upper() print(result) print(word) # do you see how lists are mutable (can append to them, can remove from them, their elements can be put in reverse order etc.) # do you see how strings are immutable (notice that word remained 'hello' after calling upper() on it) =================== 2. Treat each one separately and do the following. Read the code by eye and type up a prediction of what will print. Run the code and see if the output agrees with your prediction. If it does not, try to figure out why and explain why it works the way it does. Note: if any of these are infinitely printing, then you can use Ctrl-C to kill the program It will be easier to put these each in a python program (using File->New_File, rather than the shell.) # problem 2a. x = 1 while x <= 5: x = x + 1 print("The value of x is", x) print("The final value of x is", x) # problem 2b. x = 1 while x > 5: x = x + 1 print("The value of x is", x) print("The final value of x is", x) # problem 2c. x = 0 while x <= 0: x = x + 1 print("The value of x is " + str(x)) print("The final value of x is " + str(x)) # problem 2d. x = 0 y = 5 while x < y: x += 1 print("The value of x is " + str(x)) print("The value of y is " + str(y)) print("The final value of x is " + str(x)) print("The final value of y is " + str(y)) # problem 2e. x = 0 while x >= 0: x = x + 1 if x == 3: x = -1 print("The value of x is", x) print("The final value of x is", x) # problem 2f. #DO NOT RUN THIS ONE BECAUSE IT IS INFINITE # just read it by eye to see why it is infinite x = 0 while x < 10: print("The value of x is", x) x = x + 1 print("The final value of x is", x) # problem 2g. x = 0 while x < 10: x = x + 1 print("The value of x is", x) print("The final value of x is", x) # problem 2h. x = 0 while x < 10: print("The value of x is", x) x = x + 1 print("The final value of x is", x) =================== 3. # problem 3a. x = 1 while x <= 5: x += 1 if x > 3: break print("x is ", x) print("The final value of x is ", x) # problem 3b. for x in range(100000): if x > 3: break print("x is " + str(x)) print("The final value of x is " + str(x)) # problem 3c. for x in range(100000): if x < 3: break print("x is " + str(x)) print("The final value of x is " + str(x)) # problem 3d. for x in range(10): print("x is", x) print("The final value of x is", x) # problem 3e. for x in range(2,7): print("x is", x) print("The final value of x is", x) # problem 3f. for x in range(1,28,5): print("x is", x) print("The final value of x is", x) # problem 3g. some_list = [100,320,240,-87, 65] for i in range(len(some_list)): some_list[i] += 10 print(some_list[i]) print(some_list) # problem 3h. some_list = [100,320,240,-87, 65] for item in some_list: item += 10 print(item) print(some_list) # problem 3i. What, if anything is different in the resulting list in problems 3g vs. 3h ============ 4. Write a program named temperatures.py that asks the user, repeatedly, for temperatures until they enter 'q' for quit. Store each temperature as a float in a list as they are being entered. At the end, print the average of the temperatures entered. submit: a file containing your answers to 1,2, & 3. temperatures.py