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
Pleas pleas help and get 99 points with brainliest
storchak [24]
When you copy cells, cell references automatically adjust. But, when you move cells, cell references are not adjusted, and the contents of those cells and of any cells that point to them may be displayed as reference errors. In this case, you have to adjust the references manually.

If the selected copy area includes hidden cells, rows, or columns, Excel copies them. You may have to unhide data temporarily you don't want to include when you copy information.

Hope this helps! I'm not a computer genius though
5 0
3 years ago
Read 2 more answers
How do i install java runtime environment?
nlexa [21]
Just go to the internet and download the file and install
please mark as brainliest

3 0
3 years ago
A section at The top of the page that makes it easy for a recipient to respond to a letter is called an
Vesna [10]

its a  return address

8 0
3 years ago
Read 2 more answers
What does atx stand for?
marta [7]
Advanced technology extended
3 0
3 years ago
Read 2 more answers
The first line in a Hypertext Markup Language (HTML) file is the _____, which is a processing instruction indicating the markup
Lesechka [4]

Answer:

The appropriate answer will be "Doctype ".

Explanation:

  • Probably the DOCTYPE would not be a component or perhaps an HTML tag. It allows the app or developer to know how and where to view the text, by suggesting the HTML (and perhaps another XML language) edition or specification would be used.
  • A document type specification, or DOCTYPE, seems to be a guideline associating a specific SGML as well as an XML document with either the concept of a document.
4 0
4 years ago
Other questions:
  • What is one example of technology influencing health​
    9·1 answer
  • Using Task Manager, you discover an unwanted program that is launched at startup.
    13·1 answer
  • In general terms, a program that is broken into smaller units of code such as methods, is known as a ________
    6·1 answer
  • What is another name for a central processing unit? Computer Integrated circuit Microprocessor Transistor
    9·2 answers
  • A5.3 1012 kg satellite is 1,800 m from another satellite that has a mass of 3.5 x 108 kg. What is the gravitational
    6·1 answer
  • The definition of network is:
    10·1 answer
  • A variable like userNum can store a value like an integer. Extend the given program to print userNum values as indicated.(1) Out
    12·1 answer
  • Special keys that allow you to use the computer to perform specific functions
    5·1 answer
  • External hard drives typically connect to a computer via an external port (such as a usb or ____ port) or a wireless connection.
    15·1 answer
  • Henry wants to create a presentation for his clients. He wants to upload the presentation file directly to the Internet. Which p
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!