Python Forum
home work rolling average
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
home work rolling average
#1
Write a program that computes and prints the average of numbers in a text file. You must use at least 2 functions. The program must print each number and the rolling average of the numbers printed so far. Example shown below:


num average
90 90
100 95
50 80
75 78.75 <<<<<<<<< this is my assignment and my midterms in monday....being honest have no clue how i dont have a 0 in the class .. but ive tried and tried to get this code and python like gibberish to me i can do the basic i know how to read the five i know how to link varitiables ... i even know how to make a game play and then put it in step by step .. like i know what im sapose to do .. as making a program that has 2 define function and pull off the number file .. by looping though it and having it read each number then incriment by one adding each number then dividing by the count.. but for the life if me i can't under stand how to code it .. i have no clue on how to make a rolling average algaritem to take each number add the bottom number then divide by the number count... my primary focous is networking which i love im no programer the programing logic is something else and i really wish i could understand it the way i need to ... not asking for this to be done for me but if some one could help me understand how to make the function i need id be beyound grateful ..
Reply
#2
(Mar-02-2019, 02:32 AM)arcticfox286 Wrote: by looping though it and having it read each number then incriment by one adding each number then dividing by the count.. but for the life if me i can't under stand how to code it

That pretty much explains how to code it. Loop through the file. Convert each line to an integer. Add that integer to the total, and add one to the count. Divide the total by the count to get the average. Print the integer and the current average.

I'm not sure why they want two functions. Is there more explanation as to why? Maybe they want an average function. In that case, start with an empty list, and as each line is converted to an integer, append it to the list. Then send the list to the average function. That's incredibly inefficient, but I can't think what else they mean by using two functions.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Could someone please help walk me through my home work tetoronga 3 2,946 Mar-22-2018, 09:33 PM
Last Post: nilamo
  a Home language TDH 4 3,403 Oct-17-2017, 03:30 PM
Last Post: buran
  problem nin home work maayan11 1 2,800 Apr-27-2017, 04:01 PM
Last Post: nilamo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020