Question

High School Assignment: please keep simple, use for loops but preferably no arrays In python, Instructions...

High School Assignment: please keep simple, use for loops but preferably no arrays

In python,

Instructions

Write a program to input ten book titles and author's names then save them to a file named books.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:

TO KILL A MOCKINGBIRD    Lee, Harper
0 0
Add a comment Improve this question Transcribed image text
Answer #1

If you have any doubts please comment below. Please give upvote if you like this.

Python Code:

# we open the books.txt in write mode. You must give correct path for books.txt
with open("books.txt","w") as f:
# Loop for taking 10 books inputs
for i in range(10):
# Input for title
title = input("Enter book title: ")
# Input for first_name
first_name = input("Enter first name of author: ")
# Input for last_name
last_name = input("Enter last name author: ")
# we write the content into books.txt as per question
f.write(title.upper()+"\t"+last_name.capitalize()+", "+first_name.capitalize()+"\n")
# We open the books.txt in read mode to read the saved content
with open("books.txt","r") as f1:
# Loop for read books.txt file
for i in f1:
print(i) #Display the lines in file

Add a comment
Know the answer?
Add Answer to:
High School Assignment: please keep simple, use for loops but preferably no arrays In python, Instructions...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • In python, write the following program, high school question, please keep simple. When I submitted the...

    In python, write the following program, high school question, please keep simple. When I submitted the solution, I get an error as 'wrong answer'. Please note below the question and then the solution with compiler errors. 7.2 Code Practice: Question 2 Instructions Write a program to generate passwords. The program should ask the user for a phrase and number, and then create the password based on our special algorithm. The algorithm to create the password is as follows: If the...

  • Lab #7 CSE110 - Arizona State University Topics • Basic arrays Coding Guidelines • Give identifiers...

    Lab #7 CSE110 - Arizona State University Topics • Basic arrays Coding Guidelines • Give identifiers semantic meaning and make them easy to read (examples numStudents, grossPay, etc). • Keep identifiers to a reasonably short length. • Use upper case for constants. Use title case (first letter is upper case) for classes. Use lower case with uppercase word separators for all other identifiers (variables, methods, objects). • Use tabs or spaces to indent code within blocks (code surrounded by braces)....

  • I need help with this assignment in C++, please! *** The instructions and programming style detai...

    I need help with this assignment in C++, please! *** The instructions and programming style details are crucial for this assignment! Goal: Your assignment is to write a C+ program to read in a list of phone call records from a file, and output them in a more user-friendly format to the standard output (cout). In so doing, you will practice using the ifstream class, I'O manipulators, and the string class. File format: Here is an example of a file...

  • Mountain Paths (Part 1) Objectives 2d arrays Store Use Nested Loops Parallel data structures (i.e...

    Mountain Paths (Part 1) in C++ Objectives 2d arrays Store Use Nested Loops Parallel data structures (i.e. parallel arrays … called multiple arrays in the zyBook) Transform data Read from files Write to files structs Code Requirements Start with this code: mtnpathstart.zip Do not modify the function signatures provided. Do not #include or #include Program Flow Read the data into a 2D array Find min and max elevation to correspond to darkest and brightest color, respectively Compute the shade of...

  • Program 7 File Processing and Arrays (100 points) Overview: For this assignment, write a program that...

    Program 7 File Processing and Arrays (100 points) Overview: For this assignment, write a program that will process monthly sales data for a small company. The data will be used to calculate total sales for each month in a year. The monthly sales totals will be needed for later processing, so it will be stored in an array. Basic Logic for main() Note: all of the functions mentioned in this logic are described below. Declare an array of 12 float/doubles...

  • this needs to be in Java: use a comparator class which is passed into the sort...

    this needs to be in Java: use a comparator class which is passed into the sort method that is available on the ArrayList. import java.util.Scanner; public class Assign1{ public static void main(String[] args){ Scanner reader = new Scanner (System.in); MyDate todayDate = new MyDate(); int choice = 0; Library library = new Library(); while (choice != 6){ displayMainMenu(); if (reader.hasNextInt()){ choice = reader.nextInt(); switch(choice){ case 1: library.inputResource(reader, todayDate); break; case 2: System.out.println(library.resourcesOverDue(todayDate)); break; case 3: System.out.println(library.toString()); break; case 4: library.deleteResource(reader,...

  • I wrote some code and it builds but everytime I run it, It shows the error...

    I wrote some code and it builds but everytime I run it, It shows the error message in the else statement ASU CSE 100 Lab #7 Due date/Time: Friday, Oct. 13th, 2017 at 5:30pm What this Lab Is A Learn to create and use istream object to read data from a text file Learn to create and use ofstream object to write program output into a text file Learn to use a while loop to read a text file line...

  • Introduction to C Programming – COP 3223 1. To learn how to use arrays to store...

    Introduction to C Programming – COP 3223 1. To learn how to use arrays to store and retrieve data to help solving problems. 2. Reinforce use of input files. Introduction: Ninja Academy Ninjas are awesome! Your friend has not stopped talking about how cool ninjas and how they would like to become a ninja. To amuse your friend, you have decided to create a series of programs about ninjas. Problem: Mentorship (ninjamentors.c) It is time for your friend to select...

  • Use Java please Creating a calendar for a given year A shell for this assignment has...

    Use Java please Creating a calendar for a given year A shell for this assignment has been provided so that you can fill in the methods Homework 4 grading rubric 1. Output examples a. One Normal Year, 10% b. One Leap Year, 10% 2. Style Meaningful variable names, 10% b. Meaningful method names, 10 % c. Comments, Total: 10% . Do not comment every line. 5% . Comment non-obvious code. 5% a d. Indentation, 10% e. Block comment with name...

  • MYSQL Questions: 1.For every author, display the number of books written by that author that is...

    MYSQL Questions: 1.For every author, display the number of books written by that author that is carried by Henry Books. Display the author number as ‘Author Number’, author name concatenated (first last) as ‘Author Name’, and the total number of books written by the author as ‘Number of Titles by Author’. List in descending order by author number. Limit the output to 10 rows. Insert your snip of the query and resultset together here. 2.Using a function, what are the...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT