Write a Hmmm program average ha that repeatedly prompts for
Solution
hmmAssembler.py: To take input from file
import os
from sys import argv
try:
while 1:
filename = raw_input(\"Please enter a filename: \")
txt = open(filename)
print \"File name: \"+filename
count = 0
sum1 = 0
for line in txt:
count = count + 1
sum1 = sum1 + int(line)
print \"Average: \"+str(sum1/count)
next_file = raw_input(\"Would you like to evaluate another file? (y/n) \")
if next_file != \'y\':
break
except:
print \"File not given or error while reading file!!!\"
hmmSimulator.py: To take input from command line
import os
from sys import argv
count = 0
sum1 = 0
input1 = 0
while 1:
input1 = raw_input(\"Enter number: \")
input1 = int(input1)
if input1 != 0:
count = count+1
sum1 = sum1+int(input1)
else:
break
print \"Average: \"+str(sum1/count)

