2010-04-20, 12:18 PM
(This post was last modified: 2010-04-20, 12:25 PM by xLeviathan.)
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
This seems really ghetto/wrong. I need some input.
$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.

