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
Could someone give an example or tell me what all of these mean? (For internet source citing) Evaluation: • Domain Name: • Autho
koban [17]

Evaluation-the making of a judgment about the amount, number, or value of something; assessment

Domain Name-Is a websites name (ex-Google)

Authoritativeness-The quality of possessing authority. The quality of trustworthiness and reliability.

Accuracy-the quality or state of being correct or precise

Timeliness-the fact or quality of being done or occurring at a favorable or useful time.

Objectivity-the quality of being objective.

Writing Style and Mechanics-Style has to do with how a piece of writing sounds. Everyone has a style which develops along with their writing.

Paragraph structure: Each paragraph should begin with a topic sentence that provides an overall understanding of the paragraph. ...

Sentence length: Sentences should be kept as short as possible so that their structure is simple and readable.

Graphics-are visual images or designs

Links- is an open source text and graphic web browser with a pull-down menu system.

8 0
2 years ago
Which of these options highlights the need for learning algorithms
LiRa [457]

Answer: D.

Explanation:

7 0
3 years ago
Read 2 more answers
Whoever understands this first and replies will be the brainliest.<br><br><br><br> Road work ahead?
Scorpion4ik [409]

I SURE HOPE IT DOES (this is the best vibe if you dont get this you are an uncultured swine)

7 0
3 years ago
Read 2 more answers
What is the check digit for the following original product number: 140501941 ? *
Natasha_Volkova [10]

Explanation:

I think it is 7, but I could be wrong..... sorry

8 0
2 years ago
Read 2 more answers
A ____ resembles a circle of computers that communicate with each other.
Sidana [21]

Answer:

ring network

Explanation:

In a ring network, the nodes are arranged in a circular pattern where each node is connected to two adjacent nodes. In this topology, any node can communicate with any other node via the intermediaries.

In comparison,

- in a star network every communication needs to pass through a central hub node

- in a bus, each node is connected to a shared linear communication bus.

- in a hierarchical network nodes are organized along a tree structure layout.

4 0
3 years ago
Other questions:
  • According to your textbook, the three major criteria against which to test documents that you locate on the Internet are authors
    8·1 answer
  • Your assignment is to write an assembly language program which read a string and print it in uppercase. This program asks the us
    15·1 answer
  • A(n) ________ is a variable that receives an argument that is passed into a function. global argument scope parameter
    15·1 answer
  • Heelp my brainly stuff says i am 49 but im 11 how to fix?X??
    7·1 answer
  • PLEASE HELP ME ANSWER AS MUCH AS YOU CAN I ONLY HAVE 3 POINTS LEFT AND IM TIMED. PLEASE TELL ME THE NUMBER AND LETTER. THANK YOU
    5·1 answer
  • A) Write 600 as the product of prime factors.<br> Give your answer in index form.
    7·2 answers
  • Why is data processing done in computer
    10·1 answer
  • You are working on a graphical app, which includes multiple different shapes. The given code declares a base Shape class with an
    15·1 answer
  • Can someone write me a design brief about a stadium​
    12·2 answers
  • How do the following technologies help you with your quest to become a digital citizen kiosks enterprise computing, natural lang
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!