a06 - Assignment 6: Python Programming CSci 1001, Spring...

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

View Full Document Right Arrow Icon

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

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

Unformatted text preview: Assignment 6: Python Programming CSci 1001, Spring 2010 14 April 2010 Due date : Due by the start of class, Wednesday May 5. Overview : The five problems here will give you a variety of Python programming prac- tice. Problems range from simpler problems which should not take long, to longer or complicated problems that will require a good amount of time and thought. Because some of these problems are challenging, here are some hints. On the longer or more complicated problems, write pseudocode first, then turn it into Python. The programs will require you to use a variety of Python constructs and functions. Anything you need to use should be in the Python reference we handed out in class, and/or should have appeared in one of the examples from the class notes. If you do not see how to start a problem, remember some of the questions from the in-class exercises: what does the program need to keep track of? does it need to use a loop? an if statement? etc. Any code in this file is also posted to the class assignments page, so you can copy it from there rather than typing it in yourself. Start soon, so you have ample time to ask for help if needed. Submitting your HW : To submit your assignment, use the submit tool. You should submit a single file named named hw6.tar.gz or hw6.zip . (See the HW 5 submission instructions for more details on the submission process.) The file should contain files named hw6a.py , hw6b.py , hw6c.py , hw6d.py , and hw6e.py , corresponding to the prob- lems below. However, unlike HW 5, you need to submit only once, submitting all five of these files together. A. Completing a Short Python Program Replace each comment line below with one or two lines of Python to complete the program. 1 def myFunction(p,r,y): # if p, r, or y is negative, return 0 m = 1 while y > 0: # Set m to m times (1 + r) # Decrease y by 1 # Return p times m Once you have filled in the blanks, save your program as hw6a.py and test it with a variety of inputs, such as the following. (Youll need to figure out on your own what the correct answers should be.) print myFunction(1000, .04, 1) print myFunction(100, .02, 0) print myFunction(3000, .06, 5) print myFunction(-1, 3, 4) B. Writing a Function: Adding Lists Sometimes it is useful to add two lists together element by element. For example, suppose the list [1,5,29,0,2,2,0] tells how many times you accessed the class web page each day last week. The number of times a friend accessed the site is [1,2,3,4,5,6,7] . So to calculate how many times you both accessed the web site, you would add both your lists together, element by element: [2,7,32,4,7,8,7] ....
View Full 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 / 7

a06 - Assignment 6: Python Programming CSci 1001, Spring...

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