[Tutor] function for loaning a book
samhar zghaier
samharzghaier at gmail.com
Wed Nov 27 08:56:23 EST 2019
Hello
I creatred a function to read each of my text files and read them into the
program, im now trying to delete a certain item from one of the two lists i
created and add it to the other one
currently i am not able to add a certain element to the loan list
This is the code i have currently written
file_name = "text.txt"
loan_file = "loan.txt"
class Book():
def __init__(self, title, writer):
self.title = title
self.writer = writer
def get_book_list():
book_list = []
with open(file_name, "r") as file:
lines = file.readlines()
for line in lines:
line = line.split(",")
book_list.append(Book(line[0].strip(), line[1].strip()))
return book_list
def get_loan_list():
loan_list = []
with open(loan_file, "r") as file:
lines = file.readlines()
for line in lines:
line = line.split(",")
loan_list.append(Book(line[0].strip(), line[1].strip()))
return loan_list
def loan_book():
book_title = input("What is the name of the book")
info = book_list
for line in info:
if line.title == book_title:
loan_list.append(line)
def main():
loan_list = get_loan_list()
book_list = get_book_list()
loan_book()
main()
Help please
More information about the Tutor
mailing list