1. Write a program in python with no imports named filemaker.py that will be used to store the first name and age of some friends in a text file named friends.txt. The program must use a while loop that prompts the user to enter the first name and age of each friend. Each of these entries should be written to its own line in the text file (2 lines of data per friend). The while loop should repeat until the user presses Enter (Return on a Mac) for the name. Then, the file should be closed and a message should be displayed. See Sample Output.
Enter first name of friend or Enter to quit Denny
Enter age (integer) of this friend 24
Enter first name of friend or Enter to quit Penny
Enter age (integer) of this friend 28
Enter first name of friend or Enter to quit Lenny
Enter age (integer) of this friend 20
Enter first name of friend or Enter to quit Jenny
Enter age (integer) of this friend 24
Enter first name of friend or Enter to quit
File was created
2. Now write a program named filereader.py that reads and displays the data in friends.txt. This program should also determine 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..
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
The name of the program is filereader.py
Open the file named friends.txt
Use a variable named accumulator to do the sum of the friend’s age.
Use a variable named counter to count the friends.
In while loop
Read the data from the file named friends.txt
Do the sum of the friend's age.
Count the total friends.
Display the data from the file friends.txt
Calculate the average age of friends and display.
Close the file.
Data in friends.txt file.
The python program is:
#The name of the program is filereader.py
#open the file
file = open("friends.txt")
#accumulator is used to sum the age of the friends
accumulator = 0.0
#counter is used to count the total number of friends
counter = 0
#while loop to read the data from the file till the file is empty
#read data from file
line = file.readline()
#when all data is read then display rhe Average age of friends.
#calculate the average age of friends
avgAge = accumulator/counter
#display the average age
print("Average age of friends is %.1f"%avgAge)
Solutions are written by subject experts who are available 24/7. Questions are typically answered within 1 hour.*See Solution
Q: Question in Image. I was wondering why they are not equal even thought their contents are the same
Q: Given the assumptions above and the page table below, translate the following virtual addresses (exp...
A: Assuming the page size to be 4KB. The calculations for physical addresses are given below: (a) VA = ...
Q: Compiler returning errors with calculations and declarations. Screenshot of File.txt included. ...
A: The code is working fine as I have tested it and the Output is attached at the end.Code://importing ...
A: Program Instructions:In the function multiply2(), take one digit at a time, multiply it by two, and ...
Q: The prompt asks: Write a function that calculates the amount of money a person would earn over a per...
A: Program Approach-1)Define function named totalEarned () with years as a parameter.2)Declare and init...
Q: Explain why web application security is vital. What could happen to an insecure application? Why is ...
A: Web application securityWeb application security testing ensures that the information system is capa...
Q: Write a recursive function rec_string that produces the output shown below for the corresponding fun...
A: Program Algorithm-STARTStep1: Define the rec_string method.Step2: Compare the length of string to ze...
Q: Write a program in python with no imports named filemaker.py that will be used to store the first na...
A: Create a file named filemaker.pyPrompt user for name of a friend and his age repeatedly until user e...
Q: Exercise 1 Consider a hash table of size 13, and assume open addressing with linear probing Show ...
A: As the given size of the table is 13, as well as the number of elements to be inserted in the table...