w do I write a Python Program that determines and 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
How do I write a Python
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
fp = open("friends.txt", "w")
firstname = input("Enter first name of friend or Enter to quit ")
while firstname!="":
age = int(input("Enter age (integer) of this friend "))
print(firstname, file=fp)
print(age, file=fp)
firstname = input("Enter first name of friend or Enter to quit ")
fp.close()
print("File was Created")
Step by step
Solved in 2 steps