[Tutor] function for loaning a book

Sam samharzghaier at gmail.com
Wed Nov 27 11:06:21 EST 2019


There is no error, it’s just that it doesn’t work

Sent from Mail for Windows 10

From: William Ray Wing
Sent: Wednesday, 27 November 2019 17:04
To: samhar zghaier
Cc: William R. Wing; Tutor
Subject: Re: [Tutor] function for loaning a book



> On Nov 27, 2019, at 8:56 AM, samhar zghaier <samharzghaier at gmail.com> wrote:
> 
> 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

Please copy and paste the entire error message traceback and show us what happens.


> 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
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor




More information about the Tutor mailing list