{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

a06 - Assignment 6 Python Programming CSci 1001 Spring 2010...

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

View Full Document Right Arrow Icon
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
Image of page 1

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

View Full Document Right Arrow Icon
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. (You’ll 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] .
Image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern