Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1. Write a Hmmm program, average.ha, that repeatedly prompts for and reads in a

ID: 3925489 • Letter: 1

Question

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

Explanation / Answer

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

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote