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
Novay_Z [31]
3 years ago
5

2. Now write a program named filereader.py that reads and displays the data in friends.txt. This program should also determine a

nd print the average age of the friends on file. That will require an accumulator and a counter. Use a while loop to process the file, print the data, and modify the accumulator and counter. Then close the file and display the average age accurate to one decimal place. See the Sample Output.. SAMPLE OUTPUT My friend Denny is 24 My friend Penny is 28 My friend Lenny is 20 My friend Jenny is 24 Average age of friends is 24.0

Computers and Technology
1 answer:
Andrew [12]3 years ago
6 0

Answer:

see explaination

Explanation:

# python code filereader.py

import sys

import readline

from sys import stdin

import random

## Open the file with read only permit

f = open('inputfile.txt')

## Read the first line

sum = 0.0

count = 0

#read file till the file is empty

while True:

line = f.readline()

if ("" == line):

print "Average age of friends is", sum/count

break

list = line.split()

print "My friend ",list[0], " is", list[1]

sum = sum + int(list[1])

count = count + 1

f.close()

'''

inputfile.txt

Denny 24

Penny 28

Lenny 20

Jenny 24

output:

My friend Denny is 24

My friend Penny is 28

My friend Lenny is 20

My friend Jenny is 24

Average age of friends is 24.0

see screenshot at attachment

You might be interested in
25-words or more in your OWN words the meaning of digital literacy.
jolli1 [7]

Answer:

Digital literacy means having the skills you need to live, learn, and work in a society where communication and access to information are increasingly through digital technologies like internet platforms, social media, and mobile devices.

Explanation:

6 0
3 years ago
What is a best practice when approaching an automation effort?
Sauron [17]
Not sure bro. What’s the question reslly about?
5 0
3 years ago
Which of the following described a global network connecting billions of computers and other
zloy xaker [14]
Pretty sure its wifi
5 0
3 years ago
Read 2 more answers
What is the difference between the web and the internet?
Naddika [18.5K]
The Web is just one of the ways that information can be disseminated over the Internet
4 0
3 years ago
What impact has the wireless web had on business and society?
HACTEHA [7]
The web has changed this society in many different ways:
1. education 
2. enviormental protection 
3. news reporting 
4. social changfes
5 0
3 years ago
Read 2 more answers
Other questions:
  • Sarah has to pick images that display camera care. Which images would she pick to show camera care?
    11·1 answer
  • The main circuit board in a computer is called the ________. RAM dongle motherboard power supply unit
    14·1 answer
  • For example, sumDigits(234) returns 9 (= 2 + 3 + 4). (Hint: Use the % operator to extract digits and the / operator to remove th
    15·1 answer
  • Which of the following is a strength of fiscal policy?
    15·1 answer
  • Can someone help me on how to start this essay?
    11·2 answers
  • List two major problems that could be addressed by futuring.
    15·1 answer
  • Which of the following is referred to as "keeping up with the Joneses"?
    13·1 answer
  • Table Setting in any occasion can add to the beauty and significance of the event. It may
    6·1 answer
  • 5. What skill is unique to reading online?
    14·1 answer
  • What are the different types of topology?​ in details
    5·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!