Geocrack

dice

Jul 3rd, 2022 (edited)
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.18 KB | None | 0 0
  1. def median(dic):
  2.     number = 0
  3.     for key, value in dic.items():
  4.         number += value
  5.     return number / len(dic)
  6.    
  7.  
  8. def Roll_Analysis(file):
  9.     f = open(file, 'r')
  10.     dic = {}
  11.     for line in f:
  12.         line = line.strip()
  13.         dic[int(line.split(',')[0])] = int(str((line.split(',')[-1])))
  14.     print(dic)
  15.     f.close()
  16.     return dic
  17.  
  18.    
  19. def main():
  20.     dic = Roll_Analysis('roll.txt')
  21.     print(median(dic))
  22.  
  23. if __name__ == "__main__":
  24.     main()
  25.  
  26.  
  27.  
  28. #with a list
  29. # def median_list(list):
  30. #     number = 0 # number of rolls
  31. #     for value in list: # iterate through the list
  32. #         number += value # add the number of rolls to the total
  33. #     return number / len(list)
  34.  
  35. # def Roll_Analysis(file):
  36. #     f = open(file, 'r') # open file
  37. #     list = [] # dictionary to store the number of times each roll is made
  38. #     for line in f: # read in the file
  39. #         line = line.strip() # remove the newline character
  40. #         list.append(int(str((line.split(',')[-1]))))
  41. #     print(list)
  42. #     f.close()
  43. #     return list
  44.  
  45.  
  46. # def main():
  47. #     list = Roll_Analysis('roll.txt')
  48. #     print(median_list(list)) # print the median
  49.  
  50.  
  51. # main()
Add Comment
Please, Sign In to add comment