Answer to Question #97308 in Python for yousif

Question #97308
import os

# This program has read/write access to the WORKSPACE directory
filepath = os.path.join( os.environ['WORKSPACE'], 'yourfilename.txt' )
file = open(filepath, 'w')
Write a program to input ten book titles and authors names then save them to a file named book.txt.


For each book, the user will first input the title, then input the first name, then the last name of the author, all on separate lines. In addition to saving the books in the file, please output, using the print method, the information you've gathered from the user.

You should follow the format uppercase title, tab, capitalized last name, comma, single space, capitalized first name. Here's an example for your output:

Format:

TO KILL A MOCKINGBIRD Lee, Harper
All book titles should be in upper case and the authors name should be capitalized.
1
Expert's answer
2019-10-28T08:16:33-0400
import os
# This program has read/write access to the WORKSPACE directory


filepath = os.path.join( os.environ['WORKSPACE'], 'books.txt' )
file = open(filepath, 'w')


books_data = []
for i in range(10):
    print('%i/10. Input please...' % (i+1))
    title = input('title of the book: ')
    name = input('first name of the author: ')
    surname = input('last name of the author: ')


    books_data.append('%s\n%s\n%s' % (
        title.upper(), surname.title(), name.title()))
    print()


file.write(('\n\n').join(books_data))
file.close() 


with open(filepath, 'r') as f:
    f = f.read()


for book in f.split('\n\n'):
    print('%s\t%s, %s' % tuple(book.split('\n')))

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

Assignment Expert
03.04.20, 22:06

Dear visitor, please use panel for submitting new questions

Presley
02.04.20, 22:49

After for i in range, why are their weird symbols after the print command?

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS