Advertisement
Guest User

Untitled

a guest
Nov 19th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.19 KB | None | 0 0
  1. #Nathan Roush
  2. #11/19/2017
  3. #Lab 9-4 arrays
  4.  
  5. #the main function
  6. def main():
  7. endProgram = 'no'
  8. print
  9. while endProgram == 'no':
  10. print
  11. #declare variables
  12. pints = [0] * 7
  13. totalPints = 0
  14. averagePints = 0
  15. highPints =0
  16. lowPints = 0
  17.  
  18. #function calls
  19. pints = getPints(pints)
  20. totalPints = getTotal(pints, totalPints)
  21. averagePints = getAverage(totalPints, averagePints)
  22. highPints = getHigh (pints, highPints)
  23. lowPints = getLow(pints, lowPints)
  24. displayInfo(averagePints,highPints,lowPints)
  25.  
  26. endProgram = raw_input('Do you want to end program? (Enter nor or yes): ')
  27. while not (endProgram == 'yes' or endProgram == 'no'):
  28. print 'Please enter a yes or a no'
  29. endProgram = raw_input('Do you want to end program?(Enter no or yes): ')
  30. #the getPints function
  31. def getPints(pints):
  32. counter = 0
  33. while counter < 7:
  34. pints[counter] = input ('Enter pints collected: ')
  35. counter = counter + 1
  36. return pints
  37.  
  38. #the getTotal function
  39. def getTotal(pints, totalPints):
  40. counter = 0
  41. while counter <7:
  42. totalPints = totalPints + pints[counter]
  43. counter = counter +1
  44.  
  45. return totalPints
  46.  
  47. #the getAverage function
  48. def getAverage(totalPints, averagePints):
  49. averagePints = totalPints/7
  50. return averagePints
  51.  
  52. #the getHigh function
  53. def getHigh (highPints,pints):
  54. highPints = pints[0]
  55. counter =1
  56. while counter <7:
  57. if pints[counter]>highPints:
  58. highPints = pints[counter]
  59. counter = counter + 1
  60. return highPints
  61.  
  62. #the getLow function
  63. def getLow(lowPints, pints):
  64. lowPints = pints[0]
  65. counter =1
  66. while counter <7:
  67. if pints[counter]<lowPints:
  68. lowPints = pints[counter]
  69. counter = counter +1
  70. return lowPints
  71.  
  72. #the displayInfo function
  73. def displayInfo(averagePints, highPints, lowPints):
  74. print totalpints
  75. print 'The average number of pints donated is ',averagePints
  76. print 'The highest pints donted is ',highPints
  77. print ' The lowest pints donated is ',lowPints
  78. #calls main
  79. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement