{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Lec12Solutions

# Lec12Solutions - Today 1 Go over some midterm problems many...

This preview shows pages 1–2. Sign up to view the full content.

Today: 1) Go over some midterm problems many people missed The change leftover when someone pays \$10 to buy 7 apples at 50 cents apiece. 7 * .5 = 3.5 10 – 3.5 = 6.5 change = 10 – (7 * 0.5) Accumulator Pattern: You are trying to get your younger sibling to come inside for dinner. This recalcitrant child decides that each step, she will step half the distance to the door. Write a function that will calculate how much of the distance she has covered so far. This is the summation: ½ + ¼ + 1/8 + 1/16 + …. 1 / 2^n. Accept the number of steps as an input parameter (14 pts). Name your function distanceStepped def distanceStepped(steps): den = 2 acc = 0 for i in range(steps): acc = acc + (1 / den) # acc = acc + (1 / (2 ** i)) den = den * 2 return acc 2) “What does this print out” examples myList = [6,3,7,9,10,”Hello”,’a’,’b’,’c’] for val in range(len(myList)) print(val) for index in range(len(myList)): #print(index,myList[index]) outString = str(index) + “ “ + str(myList[index]) print(outString) print(index, end = “ “) print(myList[index]) def findMaxIndex(scores) max = scores[0]

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}