1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
aniked [119]
3 years ago
12

The steps.txt file contains the number of steps a person has taken each day for a year. There are 365 lines in the file, and eac

h line contains the number of steps taken during a day. (The first line is the number of steps taken on January 1st, the second line is the number of steps taken on January 2nd, and so forth.) Write a program that reads the file, then displays the average number of steps taken for each month. (The data is from a year that was not a leap year, so February has 28 days.)
Computers and Technology
1 answer:
Bumek [7]3 years ago
8 0

Answer:

In Python:

file = open('steps.txt', 'r')

readLine = file.readlines()

begin = 0

mdays = (31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31)

print("Month"+"\t\t"+"Average Steps")

for m in range(len(mdays)):

end = begin + mdays[m]

steps = readLine[begin:end]

sumsteps = 0

for s in steps:

 sumsteps = sumsteps + int(s)

 

average = round(sumsteps/mdays[m],1)

print(str(m+1)+"\t\t"+str(average))

begin = begin + mdays[m]

Explanation:

This line opens the step.txt file

file = open('steps.txt', 'r')

This reads the content of the file

readLine = file.readlines()

begin = 0

This initializes the months of the days to a tuple

Mmdays = (31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31)

This prints the header

print("Month"+"\t\t"+"Average Steps")

This iterates through the tuple

for m in range(len(Mmdays)):

This calculates the days in each month

end = begin + Mmdays[m]

This gets the number of steps in each month

steps = readLine[begin:end]

This initializes the number of steps to 0

sumsteps = 0

This iteration sums up the number of steps in each month

<em> for s in steps: </em>

<em>  sumsteps = sumsteps + int(s) </em>

This calculates the average of steps rounded to 1 decimal place  

average = round(sumsteps/Mmdays[m],1)

This prints the calculated average

print(str(m+1)+"\t\t"+str(average))

This calculates the beginning of the new month

begin = begin + Mmdays[m]

You might be interested in
Which of the following is used to allocate memory for the instance variables of an object of a class?1. the reserved word public
kodGreya [7K]

Answer:

The correct answer to the following question will be 2. the operator new.

Explanation:

New operator is used to allocating the memory to the instance object.The new object can be created by using a "new" keyword in java .

Syntax of using 'new' operator is :

class_name object_name=new class_name() // it allocated the memory to the class

For Example :

ABC obj = new ABC;  

Now, this time obj points to the object of the ABC class.

obj = new ABC ();

call the construction of ABC class

3 0
3 years ago
Kenny works with an IT company. His company is about to launch new software in the market. He has to ensure that this new softwa
butalik [34]

The job profile that Kenny is likely to have is  software analyst.

<h3>What is a job profile?</h3>

This is known to be that which states the details of an employee in regards to their  job.

Note that a software analyst is known to be that person who examines and maintain the software development process, carry out configuration management, and others.

So, The job profile that Kenny is likely to have is  software analyst.

Learn more about job profile from

brainly.com/question/3700565

#SPJ1

7 0
2 years ago
The accounting number format function is contained within the __________.
bija089 [108]
The accounting number format shows numbers with a dollar sign on one side of the number, embeds a comma each three positions to one side of the decimal point, a presentations numbers to the closest cent. Hope this will help.
8 0
3 years ago
The content of a 4-bit register is initially the 4-bit word 0101. the register is shifted 6 times to the right with the serial i
Slav-nsk [51]

what is this concept?

3 0
3 years ago
What is a Font? I need help please
aleksklad [387]

Answer:

This is the answer, see which is best suited

4 0
3 years ago
Other questions:
  • Craig's annual take-home pay is $75,000. What is the maximum amount that he can spend per month paying off credit cards and loan
    7·2 answers
  • Name that red flag asigment
    15·2 answers
  • HELP 10 POINTS
    5·1 answer
  • An image that has been saved in Tagged Image File Format (or .TIF) is A. readable only by Windows personal computers. B. a recto
    6·1 answer
  • How do you respond to an email?
    6·1 answer
  • What do you need to do before you can sort and filter data in a data base?
    12·1 answer
  • Hi, I just have a few questions from my digital tech assignment.
    14·2 answers
  • Given that n refers to a positive int use a while loop to compute the sum of the cubes of the first n counting numbers, and asso
    12·1 answer
  • The operating system (OS) of an information system contains the software that executes the critical functions of the information
    6·1 answer
  • Ginny faced an application error while executing the recorder in opera. Which web browser is generally recommended to use with r
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!