1 Write a Hmmm program averageha that repeatedly prompts for

1. Write a Hmmm program, average.ha, that repeatedly prompts for and reads in a sequence of integers and prints their average (rounded down, since we are dealing with integers) and prints the remainder (possibly 0). To mark the end of your sequence, enter 0. This last 0 should not be counted in the average (ie don\'t count it as an entry). Eg $ python hmmmAssembler.py Enter input file name: average.ha $ python hmmmS1mulator.py Enter debugging mode? no Enter number: 12 Enter number: 14 Enter number: 15 Enter number: 13 2 Note: if just a 0 is entered, nothing should be printed. s python hmmmSimulator.py Enter debugging mode? no

Solution

The followng Python program accepts input from user and return the average and remainder.

import math
import sys
import os

num1 = raw_input(\"enter number: \")

num=int(num1)

if num == 0:
    quit()
else:
    myarr=[]
    while num !=0:
  
        myarr.append(num)

        num1=raw_input(\"enter number: \")
        num=int(num1)
    sum=0
    avg=0
    totnum= len(myarr)
    for i in range(0,len(myarr)):
        sum=int(sum+ myarr.pop())
  
    avg =int(sum/totnum)
    rem=int(sum%totnum)
      
    print avg
    print rem

 1. Write a Hmmm program, average.ha, that repeatedly prompts for and reads in a sequence of integers and prints their average (rounded down, since we are deali

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site