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
What is a collection of information in a<br> row representing one object called?
Pie
Record in terms of ict
8 0
2 years ago
An oil company is investigating whether they are likely to find oil at a certain site. They will use an expert system to help th
11Alexandr11 [23.1K]
The expert system are given inputs such as questions, locations and information. The expert system processes and advice the user on what to do. If the user inputs the location of an oil site and ask a question if they are able to drill an oil out of the site, then the expert system calculates and gives you the answer you need. Though the expert system makes errors just like humans.
6 0
3 years ago
How operands are fetched from or stored into memory using different ways?
Mila [183]
<span>The operand is part of the instruction and is fetched from code memory following the instruction opcode.
</span><span>The value is stored in memory, and the specific address is held in a register</span>
6 0
4 years ago
What does it mean when your check engine light comes on?
Ludmilka [50]
This website has an article about the on-board diagnostics system (OBD system) which turns on the Check Engine light in a motorized vehicle: https://motorist.org/articles/check-engine-light

Hope it helps you!
5 0
4 years ago
Whois the person start programming​
Mrrafil [7]

Answer:

The first computer programming language was created in 1883, when a woman named Ada Lovelace worked with Charles Babbage on his very early mechanical computer, the Analytical Engine.

4 0
3 years ago
Other questions:
  • _______ is malware that encrypts the user?s data and demands payment in order to access the key needed to recover the informatio
    6·1 answer
  • When was the airplane invited
    11·2 answers
  • Write a C++ program that overloads a function named LinearSearch that searches an array of data of either integer data type, flo
    8·1 answer
  • _____ should be scanned for viruses
    13·2 answers
  • What does a proxy server do?
    5·2 answers
  • Refer to the following statement: “We have implemented several IT solutions:
    14·1 answer
  • A network technician is designing a network for a small company. The network technician needs to implement an email server and w
    12·1 answer
  • Why is there no I do you time of day when all students should study
    10·1 answer
  • What is difference between computer and smartphone
    15·1 answer
  • What is the grooming process as it relates to online predators
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!