a06-key - Assignment 6: Python Programming ANSWER KEY CSci...

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

View Full Document Right Arrow Icon
Assignment 6: Python Programming ANSWER KEY CSci 1001, Spring 2010 7 May 2010 Remember that writing code is a creative process, so for problems B, D, and E, there may be multiple correct ways of solving the problem. The solution we’ve presented is only one possible solution. If you received full points, your solution is correct as well. A. Completing a Short Python Program def myFunction(p,r,y): if p<0 or r<0 or y<0: return 0 m = 1 while y > 0: m = m * (1 + r) y = y - 1 return p * m B. Writing a Function: Adding Lists def listAdder(a1, a2): #Complete the listAdder function here. sumList = [] if len(a1) != len(a2): print "These lists cannot be added", else: for i in range(0, len(a1)): sumList.append(a1[i] + a2[i]) return sumList 1
Background image of page 1

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

View Full DocumentRight Arrow Icon
# main test program print listAdder([1,2,3], [1,1,1]) print listAdder([2,2,2,2], [1,2,2]) print listAdder([7,5,5,3], [1,4,5,2]) #Add at least four more good test cases here. print listAdder([], []) print listAdder([20,2,15,34], [17,92,26]) print listAdder([7,5,5,3,54,21,68,49,21], [1,2,32,4,12,17,4,5,2]) print listAdder([17, 2], [1009,47]) C. Turning Pseudocode to Python def checkUPC(testNumber): placeIsOdd = True sum = 0 while (testNumber > 0): currentDigit = testNumber % 10 if placeIsOdd == True: sum = sum + currentDigit else: sum = sum + 3 * currentDigit if placeIsOdd == True: placeIsOdd = False else: placeIsOdd = True testNumber = testNumber/10
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 10/28/2010 for the course CSCI 1001 taught by Professor Staff during the Spring '08 term at Minnesota.

Page1 / 9

a06-key - Assignment 6: Python Programming ANSWER KEY CSci...

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

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