Quick question-i am trying to write a programs whcih calculates the average of the numeric values of words that appear multiple times (if a word appears more than once then i want the average of its values). I do not get an error but instead only the sum of each word's value.This is the input of the program:
So the output will have 9 lines since it will integrate the first two and find their average value. My problem is that my code doesn't work properly. I mean, i do get any errors but it doesn't seem to perform the dividion in order to find the average value.
This is what i ve written so far:
f=open('example.txt','r') for line in f: words = line.split() if len(words) == 2: count = 1 word = words cvalue = float(words) if word not in wordsdict: wordsdict[word] = cvalue else: count += 1 wordsdict[word] = sum([cvalue,wordsdict[word]]) average = wordsdict[word] / count elif len(words) == 3: word = words + " " + words  cvalue = float(words) if word not in wordsdict: wordsdict[word] = cvalue else: count += 1 wordsdict[word] = sum([cvalue,wordsdict[word]]) average = wordsdict[word] / count
Any thoughts of why this is happening? I may miss something because i am new in python:$