Advertisement
Thewhitemagic1488

Untitled

Jan 17th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.68 KB | None | 0 0
  1. ###########################################################################################
  2. # Name: Seth O'Quin
  3. # Date: 1/17/18
  4. # Description: Casual Statistics
  5. ###########################################################################################
  6.  
  7. # function that prompts the user to enter an integer and returns it
  8. def getInteger():
  9. integer = input("Enter an integer: ")
  10. return integer
  11.  
  12. # function that receives three integers as parameters and returns the minimum of the three
  13. def minofThree( x, y, z):
  14. minnum = x
  15. if y < minnum:
  16. minnum = y
  17. if z < minnum:
  18. minnum = z
  19. print "The minimum value is {}." .format(minnum)
  20.  
  21. # function that receives three integers as parameters and returns the maximum of the three
  22. def maxofThree( x, y, z):
  23. maxnum = x
  24. if y > maxnum:
  25. maxnum = y
  26. if z > maxnum:
  27. maxnum = z
  28. print "The maximum value is {}." .format(maxnum)
  29.  
  30.  
  31. # function that receives three integers as parameters, and calculates and returns the mean
  32. def meanofThree( x, y, z):
  33. mean = (x + y + z)/3.0
  34. print "The mean is {}." .format(mean)
  35.  
  36. # function that receives three integers as parameters, and calculates and returns the median
  37. def medianofThree( x, y, z):
  38.  
  39.  
  40. # function that receives three integers as parameters, and calculates and returns the mode
  41. def modeofThree( x, y, z):
  42. if (x == y):
  43. print "The mode is {}." .format(x)
  44. elif (x == z):
  45. print "The mode is {}." .format(x)
  46. elif (y == z):
  47. print "The mode is {}." .format(y)
  48. else:
  49. print "The mode is undefined."
  50.  
  51.  
  52. # function that receives three integers as parameters, and calculates and returns the range
  53. def rangeofThree( x, y, z):
  54. small = x
  55. if (small > y):
  56. small = y
  57. if (small > z):
  58. small = z
  59. large = x
  60. if (large < y):
  61. large = y
  62. if (large < z):
  63. large = z
  64. rangexyz = (large - small)
  65. print "The range is {}." .format(rangexyz)
  66.  
  67.  
  68.  
  69. ###############################################
  70. # MAIN PART OF THE PROGRAM
  71. # implement the main part of your program below
  72. # comments have been added to assist you
  73. ###############################################
  74. # get three integers from the user
  75. x = getInteger()
  76. y = getInteger()
  77. z = getInteger()
  78.  
  79. # determine and display the minimum value
  80. minofThree( x, y, z)
  81.  
  82. # determine and display the maximum value
  83. maxofThree( x, y, z)
  84.  
  85. # calculate and display the mean
  86. meanofThree( x, y, z)
  87.  
  88. # calculate and display the median
  89.  
  90.  
  91. # calculate and display the mode
  92. modeofThree( x, y, z)
  93.  
  94. # calculate and display the range
  95. rangeofThree( x, y, z)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement