pennyadayrev


SUBMITTED BY: Guest

DATE: Nov. 16, 2013, 3:38 a.m.

FORMAT: Text only

SIZE: 1.8 kB

HITS: 1036

  1. """
  2. Joshua Miller
  3. pennyaday.py 8-1
  4. """
  5. """
  6. col #1 - day
  7. col #2 - day pay
  8. col #3 - to date pay
  9. 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.
  10. 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 a two dimensional array and the results printed from that array.
  11. The output should be displayed in a dollar amounts, not the number of pennies.
  12. A minimum of three modules should be used for this problem.
  13. Hint: Each day of work would be represented by a row. Column 1 would be the day count, column 2 the current day's pay and column 3 the accumulated pay.
  14. **Use comments to document the python program
  15. """
  16. from isNumeric import *
  17. from numpy import *
  18. def main():
  19. days = raw_input("How many days would you like to calculate for this? ")
  20. days = int(days)
  21. pay = zeros([days,3],float)
  22. pay = calculate(days,pay)
  23. print pay
  24. outputScreen(days,pay)
  25. def calculate(days, pay):
  26. pay[0,0] = 1
  27. pay[0,1] = 0.01
  28. pay[0,2] = 0.01
  29. for i in range(1,days,1):
  30. pay[i,0]= i+1
  31. pay[i,1] = pay[i-1,1] * 2
  32. pay[i,2] = pay[i-1,2] + pay[i,1]
  33. return pay
  34. def outputScreen(days,pay):
  35. print "#1 #2 #3 "
  36. for i in range(0,days,1):
  37. print pay[i,0], " ", pay[i,1], " ", pay[i,2]
  38. if __name__ == "__main__":
  39. main()

comments powered by Disqus