Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python Help.
#1
This is for a friend who asked me to help. I know nothing about Python or Wing IDE (Which I'm guessing they use in that class).

$5 via PayPal to whoever does this for me. No joke. :O


Quote:CIS115 Introduction to Programming & Logic

Lists / Arrays

Design & write a python program that calculates the amount of money a person would earn over a period of time if his or her salary is one penny the first day, two pennies the second day and continues to double each day. The only input to the program should be the number of days to calculate. The day number, amount of pay for each day and the accumulated amount of pay should be stored in 3 parallel lists. The output should be displayed in a dollar amounts, not the number of pennies.

A minimum of three modules should be used for this problem. The program must also loop for additional input and provide for user termination of the program.

Code:
#!/usr/bin/env python

# Return the salary at any given day
# If given an empty list as second parameter,
# it would also store the total accumulated amount of pay
def salary(day, accumulated=None):
    if day == 1:
        if accumulated != None:
            accumulated.append(1)
        return 1
    n = 2 * salary(day - 1, accumulated)
    if accumulated != None: accumulated.append(n)
    return n

# Read from command line should be done here, as well as parsing
# e.g.
from sys import stdin
try:
    days = int(stdin.readline())
    listofdays = range(1,days)
    accumulated = []
    salary(days, accumulated)
except:
    print "Goodbye"

This seems really ghetto/wrong. I need some input.
Reply


Messages In This Thread
Python Help. - by xLeviathan - 2010-04-20, 12:18 PM
Python Help. - by Fiel - 2010-04-20, 12:26 PM
Python Help. - by xLeviathan - 2010-04-20, 12:30 PM
Python Help. - by Fiel - 2010-04-20, 01:21 PM
Python Help. - by xLeviathan - 2010-04-20, 07:40 PM
Python Help. - by Russt - 2010-04-20, 08:36 PM
Python Help. - by xLeviathan - 2010-04-21, 08:20 AM

Forum Jump:


Users browsing this thread: 1 Guest(s)