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
Ximena noticed that Sofia had created a network bridge on her new laptop between the unsecured wireless network and the organiza
ratelena [41]

Answer:

A bridge could permit access to the secure wired network from the unsecured wireless network

Explanation:

A bridge is connecting device in networking that connects two different network devices. This device is suitable to connect a secure network with an unsecured network.

8 0
3 years ago
#Write a function called "scramble" that accepts a string #as an argument and returns a new string. The new string #should start
mojhsa [17]

Answer:

def scramble(s):

   if len(s) % 2 == 1:

       index = int(len(s)//2)

   else:

       index = int(len(s)/2)

   

   return s[index:] + s[:index]

Explanation:

Create a function called scramble that takes one parameter, s

Check the length of the s using len function. If the length is odd, set the index as the floor of the length/2. Otherwise, set the index as length/2. Use index value to slice the s as two halves

Return the second half of the s and the second half of the s using slice notation (s[index:] represents the characters from half of the s to the end, s[:index] represents the characters from begining to the half of the s)

8 0
3 years ago
Write a program to input the TotalCost and display the Assured gift as per the following criteria TotalCost(TC) Assured Gift Les
Yanka [14]

Answer:

The program in Python is as follows:

TotalCost = int(input("Total cost: "))

if TotalCost <= 2000:

   print("Wall Clock")

elif TotalCost >= 2001 and TotalCost <= 5000:

   print("School Bag")

elif TotalCost >= 5001 and TotalCost <= 10000:

   print("Electric Iron")

else:

   print("Wrist Watch")

Explanation:

This gets input for total cost

TotalCost = int(input("Total cost: "))

If the total cost is up to 2000, print wall clock as the assured gift

<em>if TotalCost <= 2000:</em>

<em>    print("Wall Clock")</em>

If the total cost is between 2001 and 5000 (inclusive), print school bag as the assured gift

<em>elif TotalCost >= 2001 and TotalCost <= 5000:</em>

<em>    print("School Bag")</em>

If the total cost is between 5001 and 10000 (inclusive), print electric iron as the assured gift

<em>elif TotalCost >= 5001 and TotalCost <= 10000:</em>

<em>    print("Electric Iron")</em>

If the total cost is more than 10000, print wrist watch as the assured gift

else:

   print("Wrist Watch")

8 0
3 years ago
An input value has to be greater than 18 and less than 65 if a driving license is to be approved for issue. What type of input c
katrin2010 [14]

Answer:

You should use an "if" statement to check whether the number is greater than 18 or less than 65.

Explanation:

You usually use "if" statements whenever you want to compare a number to another. Keep in mind that "if" statements are not only used for comparison!

4 0
3 years ago
The two most popular forms of animation today are Disney animation and Japanese anime. Each style differs from the other in many
adoni [48]

Answer:

The animation industry has been booming over the past few decades but there have been two animation genres that have stood out from the rest those being the american children's cartoon empire disney and the Japanese industry called anime. One is geared more towards children whilst the other is centered more towards adults. Though these industries may be very different, they both have drawn in a large audience from all around the world. The impacts upon society as a whole are vast and some, unknown.

I wrote a good introductory paragraph hopefully it helps i'm busy now so I can't continue to write your essay hopefully this makes things easier for you

5 0
2 years ago
Other questions:
  • Jim, the IT director, is able to complete IT management task very well but is usually two weeks late in submitting results compa
    5·1 answer
  • Which of the following is NOT true about variables?
    13·1 answer
  • To print a range of cells in the active worksheet, click ____ in the settings area in the print gallery.
    14·1 answer
  • Which of the following code segments does not contain any errors?
    7·1 answer
  • To convert microseconds to nanoseconds: a. Take the reciprocal of the number of microseconds. b. Multiply the number of microsec
    13·1 answer
  • The blank method returns an integer between the two provided numbers. It can take the value of either of the provided numbers
    12·1 answer
  • Write a program that assigns values to
    15·1 answer
  • The type of line shown below represents an / a:​
    11·1 answer
  • How do I use this site?brainly.com
    12·1 answer
  • 10.
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!