Lec12Solutions

Lec12Solutions - Today: 1) Go over some midterm problems...

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

View Full Document Right Arrow Icon
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])
Background image of page 1

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

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 3

Lec12Solutions - Today: 1) Go over some midterm problems...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online