What to do to correct the error written below:

Peter Pearson pkpearson at nowhere.invalid
Mon Apr 11 10:28:51 EDT 2022


On Mon, 11 Apr 2022 00:14:49 -0700 (PDT), NArshad wrote:
[snip]
>         books = list(models.Book.objects.filter(isbn=i.isbn))
>         students = list(models.Student.objects.filter(user=i.student_id))
>         i=0
>         for l in books:
>             t=(students[i].user,students[i].user_id,books[i].name,books[i].isbn,issuedBooks[0].issued_date,issuedBooks[0].expiry_date,fine)
>             i=i+1
>             details.append(t)
[snip]

Is this homework?  In this newsgroup, by custom, homework problems
should be announced as such, since the best answer to a homework
question is different from the best answer to a real-life problem.

Back to the problem:

By looping over elements in "books" and incrementing counter i,
which is used as an index both for "books" and for "students",
you will produce an error whenever the number of books exceeds
the number of students.  Is there some reason to assume that the
number of books cannot exceed the number of students?



-- 
To email me, substitute nowhere->runbox, invalid->com.


More information about the Python-list mailing list