I have a problem in reading the text files in python. Below will describe things that im doing and what im stuck at:
This part functions to read user input and store it inside the textfile bookdata.txt. This part have no error in it.
bookdata = open("bookdata.txt","a")
Author = input("Author's Name: ")
title = input("Book Title: ")
keyword = input("Book Keyword: ")
publisher = input("Publisher: ")
year = input("Year Publish: ")
# write user input into "bookdata.txt"
bookdata.write("Author's Name: " + Author + "\n")
bookdata.write("Book Title: " + title + "\n")
bookdata.write("Keyword: " + keyword + "\n")
bookdata.write("Publisher: " + publisher + "\n")
bookdata.write("Year Published: " + year + "\n\n")
bookdata.close() #closes textfile "bookdata.txt"
My second objective is to read the user input from the textfile bookdata.txt. This is the problematic part. Here is my code:
print("************** Search By **************")
print("\t[1] Search By Author")
print("\t[2] Search by Title")
print("\t[3] Search by Keyword")
print("\t[4] Go back")
print("***************************************")
searchby = input("Enter Search By Option: ")
if searchby == "1":
#search author
elif searchby == "2":
#search title
elif searchby == "3":
#search keyword
elif searchby == "4":
i dont know how to read user input. For example, If i search by author, all of the related user input (author, title, keyword, etc...) will show. Does anyone know any method for doing this? Thank you in advance.