Python Forum

Full Version: how to put text file in a dictionary
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
A library maintains its book information (stock) in a text file. An application needs to be developed which will read the text file and display all the books available for borrowing. Then with each transaction (borrowing) a note should be generated for the particular borrower and should be written into a file. The stock of the books should also be updated after each transaction. For example, if the library had 10 books of specific title, then if one of those books is borrowed then the number should change to 9. In the case of returning a book, a note should again be generated for the person returning the book. The stock should also be updated i.e. the quantity of the book returned should be increased by 1. A sample format of the text file containing the information about the books is as follows:
Harry Potter, JK Rowling, 30, $2
Start With Why, Simon Sinek, 10, $1.5
Programming With Python, John Smith, 20, $1.5

*1st column contains the name of the book, 2nd column contains the name of the author, 3rd column contains the quantity available, 4h column contains the price for borrowing the book (for duration of 10 days) **You can use your own format and add other information too A note should be generated for each transaction. When a person borrows a book a note should be generated which must contain the name of the borrower, the name of the book borrowed, the date and time of such issue and the total amount to be paid for the borrowing. If a person decides to borrow multiple books then all the borrowed books should be written to the note and the amount should be added up for all the borrowed books. When a person returns a book to the library, a note should be generated and written to the file again. The note should contain the name of the borrower, name of the book, date and time of the return. The lending duration should be set to 10 days, and a person is late in return the book, a fine should be applied on a daily basis which should also be present in the generated file.
What have you tride? We're not going to write your code for you, but we would be glad to help you fix your code when you run into problems. When you do run into problems, be sure to post your code in Python tags, and clearly explain the problem you are having, including the full text of any errors.
I didn't read through that whole thing but it looks like you just copy-pasted your homework. We're not going to do it for you, but we would love to help. What you need to do is give it a try, and then when you get stuck, post your code (in code tags) along expected vs. actual output (hard-coded any relevant inputs). Usually no more than 5-10 lines are needed to demonstrate a problem, even for large code. The more simplified your question, the more likely you'll get a speedy and helpful reply.