in python1. Write a program 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.SAMPLE OUTPUTEnter first name of friend or Enter to quit DennyEnter age (integer) of this friend 24Enter first name of friend or Enter to quit PennyEnter age (integer) of this friend 28Enter first name of friend or Enter to quit LennyEnter age (integer) of this friend 20Enter first name of friend or Enter to quit JennyEnter age (integer) of this friend 24Enter first name of friend or Enter to quitFile was created

Question
Asked Sep 30, 2019

in python

1. Write a program 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.
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

check_circle

Expert Answer

Step 1

Program code:

...
#file open
open ("friends.txt", "w")
iterate a while loop
W =
while True:
#scan for the input
input ("Enter first name of friend or Enter to
quit ")
name
#if condition
if name
break
#scan for the input
input ("Enter age (integer) of this friend ")
age
write to the file
w. write (name "\n")
#write to the file
w.write(age "\n")
close the file
w.close ()
#print the statement
print ("File was created")
help_outline

Image Transcriptionclose

#file open open ("friends.txt", "w") iterate a while loop W = while True: #scan for the input input ("Enter first name of friend or Enter to quit ") name #if condition if name break #scan for the input input ("Enter age (integer) of this friend ") age write to the file w. write (name "\n") #write to the file w.write(age "\n") close the file w.close () #print the statement print ("File was created")

fullscreen

Want to see the full answer?

See Solution

Check out a sample Q&A here.

Want to see this answer and more?

Solutions are written by subject experts who are available 24/7. Questions are typically answered within 1 hour.*

See Solution
*Response times may vary by subject and question.
Tagged in

Engineering

Computer Science

Related Computer Science Q&A

Find answers to questions asked by student like you

Show more Q&A add
question_answer

Q: Write a program that contains 2 methods, main and printLine (10 points)1) The printLine method will ...

A: Declare required variables ‘first’, ‘second’ and ‘times’ which is used to store first character, sec...

question_answer

Q: Develop the ‘Shape’ application such that: ‘Rectangle’, ‘Ellipse’, and ‘Triangle’ classes inherit f...

A: Program plan:Define a class named “Shape”.Define a default constructor to print constructor invoked ...

question_answer

Q: Try giving these 2 commands $ echo cat$ cat echoExplain the differences between the output of each c...

A: echo command:echo command is used to display the line of text passed as an argument. It is a built i...

question_answer

Q: Consider the following procedure: procedure mystery (x, y, z); integer x, y, z;beginz = 2; y= z+x;en...

A: Pass by reference copies the location of argument to the parameter. Hence, the final value of n, A[1...

question_answer

Q: Design a Turing machine that computes the function f (x) = x − 2 if x > 2   = 0 i...

A: Click to see the answer

question_answer

Q: This program uses hours, pay rate, state tax and fed tax to determine grossand net pay. The code is ...

A: Program Descriptions:The given program does not have any errors.It takes input from a file named pay...

question_answer

Q: You are not required to execute the queries. However, your syntax must by accurate.You must give at ...

A: Hey, since there are multiple sub-part questions posted, we will answer first three questions. If yo...

question_answer

Q: (Method Overloading) Given the following methods, write down the printed output of themethod calls: ...

A: Answer with Explanation:“doSomething(5)” contains an argument integer “5” and it is called to the “d...

question_answer

Q: What is the difference between Computer Science and Computer Engineering?

A: Difference between computer science and computer engineeringBoth computer science and engineering be...