Advertisement
Antypas

MaxMinMean

Apr 15th, 2020
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.20 KB | None | 0 0
  1. #Maximum, Minimum, and Arithmetic Mean
  2.  
  3. import random  #just to generate test data
  4.  
  5. def maximum(list):
  6.     temp = []
  7.     for index in range(len(list)):
  8.         temp.append(list[index])
  9.     for index in range(len(temp)-1):
  10.         if temp[0] >= temp[1]:
  11.             temp.pop(1)
  12.         elif temp[0] < temp[1]:
  13.             temp.pop(0)
  14.     maximum = temp[0]
  15.    
  16.     return maximum
  17.  
  18. def minimum(list):
  19.     neg_list =[]
  20.     for index in range(len(list)):
  21.         neg_list.append(-list[index])
  22.     minimum = -maximum(neg_list)
  23.    
  24.     return minimum
  25.  
  26. def mean_arithmetic(list):
  27.     sum = 0
  28.     for index in range(len(list)):
  29.         sum += list[index]
  30.     arithmetic_mean = sum/len(list)
  31.    
  32.     return arithmetic_mean
  33.  
  34.  
  35. def statistics_stuff(N):
  36.     print(N)
  37.     print("maximum > ", maximum(N))
  38.     print("minimum > ",minimum(N))
  39.     print("arithmetic mean > ", mean_arithmetic(N))
  40.  
  41. #####################################
  42. # "Create" a list of scores, randomly
  43. scores = []
  44. for x in range (0, 30):
  45.   scores.append(random.randint(0, 10))
  46.  
  47.  
  48. N = [-15, 4, 8, 46,-2, 123, 75]
  49.  
  50. #####################################
  51.  
  52. statistics_stuff(scores)
  53. print("another example")
  54. statistics_stuff(N)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement