Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def median(dic):
- number = 0
- for key, value in dic.items():
- number += value
- return number / len(dic)
- def Roll_Analysis(file):
- f = open(file, 'r')
- dic = {}
- for line in f:
- line = line.strip()
- dic[int(line.split(',')[0])] = int(str((line.split(',')[-1])))
- print(dic)
- f.close()
- return dic
- def main():
- dic = Roll_Analysis('roll.txt')
- print(median(dic))
- if __name__ == "__main__":
- main()
- #with a list
- # def median_list(list):
- # number = 0 # number of rolls
- # for value in list: # iterate through the list
- # number += value # add the number of rolls to the total
- # return number / len(list)
- # def Roll_Analysis(file):
- # f = open(file, 'r') # open file
- # list = [] # dictionary to store the number of times each roll is made
- # for line in f: # read in the file
- # line = line.strip() # remove the newline character
- # list.append(int(str((line.split(',')[-1]))))
- # print(list)
- # f.close()
- # return list
- # def main():
- # list = Roll_Analysis('roll.txt')
- # print(median_list(list)) # print the median
- # main()
Add Comment
Please, Sign In to add comment