Advertisement
Guest User

Untitled

a guest
Aug 23rd, 2019
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.59 KB | None | 0 0
  1. import os
  2.  
  3. filename = None
  4. metric = None
  5. action = None
  6.  
  7. def read(filename):
  8.     with open(filename) as file:
  9.             filecontents = file.read()
  10.  
  11.     print(filecontents)
  12.  
  13. def column(filename):
  14.     with open(filename, 'r') as f:
  15.         results []
  16.         for line in f:
  17.             words = line.split(',')
  18.             results.append((words[0], words[1:]))
  19.  
  20.  
  21.  
  22.  
  23.             #results.append((words[0], words[1:]))
  24.        # print(results)
  25.  
  26. #def min_calculation():
  27.  
  28. #def mean_calculation()
  29. #def median_calculation():
  30. #def harmonic_mean_calculation():
  31.  
  32.  
  33. def calculation(metric,action):
  34.  
  35.     if action == "list":
  36.         if metric == "min":
  37.             action == None
  38.         elif metric == "mean":
  39.             action == None
  40.         elif metric == "median":
  41.             action == None
  42.         elif metric == "harmonic mean":
  43.             action == None
  44.     elif action == "correlation":
  45.         if metric == "min":
  46.             action == None
  47.         elif metric == "mean":
  48.             action == None
  49.         elif metric == "median":
  50.             action == None
  51.         elif metric == "harmonic mean":
  52.             action == None
  53.  
  54.     # DO CAPITAL LETTERS AND SPACE CHECK
  55.  
  56. def file_noexist(filename):
  57.     if not os.path.isfile(filename):
  58.         filename = input("This file does not exist, please enter the name of the file you wish to read ").lower().strip()
  59.         file_noexist(filename)
  60.  
  61. def metric_noexist(metric):
  62.     if metric not in {"min", "mean", "median", "harmonic mean"}:
  63.         metric = input("Incorrect choice, please choose a metric from min, mean, median, harmonic mean ").lower().strip()
  64.         metric_noexist(metric)
  65.  
  66. def action_noexist(action):
  67.     if action not in {"list","correlation"}:
  68.         action = input(
  69.             "Incorrect choice, please chose an action to be performed on the data using the specified metric. "
  70.             "Options are list, correlation ").lower().strip()
  71.         action_noexist(action)
  72.  
  73. def userinput():
  74.     filename = input("Enter the name of the file you wish to read ").lower().strip()
  75.     file_noexist(filename)
  76.  
  77.     metric = input("Please choose a metric from min, mean, median, harmonic mean ").lower().strip()
  78.     metric_noexist(metric)
  79.  
  80.     action = input("Chose action to be performed on the data using the specified metric. Options are list, correlation ").lower().strip()
  81.     action_noexist(action)
  82.  
  83.     return filename, metric, action
  84.  
  85.  
  86.  
  87. def main():
  88.     filename, metic, action = userinput()
  89.     read(filename)
  90.     column(filename)
  91.     calculation(metric,action)
  92.  
  93. if __name__ == "__main__":
  94.     main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement