0

Hi I'm getting the error TypeError: argument of type 'int' is not iterable when i run my program and don't know where I'm going wrong.

My code is:

class loan:

    global loanlist
    loanlist = []

    def loanbook(self, name, ISBN, author, title):
	self.name = name
	self.ISBN = ISBN
	self.author = author
	self.title = title
	self.data = loanlist.append(self.name)
	self.data = loanlist.append(self.ISBN)
	self.data = loanlist.append(self.author)
	self.data = loanlist.append(self.title)

class book:

    global booklist
    booklist = []

    def addbook(self, ISBN, author, title, stock):
	self.ISBN = ISBN
	self.author = author
	self.title = title
	self.stock = stock
	self.data = booklist.append(self.ISBN)
	self.data = booklist.append(self.author)
	self.data = booklist.append(self.title)
	self.data = booklist.append(self.stock)

class library:

    def issamebook(self, name, ISBN, author, title):
	for i in range(len(booklist)):
	    if ISBN in booklist[i]:
	        if author in booklist[i+1]:
		    if title in booklist[i+2]:
		        print "Found book match at position ", i
			booklist[i+3] = booklist[i+3] - 1
		    else:
		        print "book not found"
	        else:
		    pass
	    else:
	        pass

if __name__ == "__main__":
    a=book()
    a.addbook("1234", "John", "Book 1", 1)
    a.addbook("2345", "Jim", "Book 2", 1)
    print booklist
    b=loan()
    b.loanbook("Steven", "1234", "John", "Book 1")
    b.loanbook("Tom", "2345", "Jim", "Book 2")
    print loanlist
    c=library()
    c.issamebook("Steven", "1234", "John", "Book 1")
    print booklist

Can someone give me a clue on what to do. Thanks.

2
Contributors
3
Replies
4
Views
8 Years
Discussion Span
Last Post by Ene Uran
0

I forgot to mention the error message occurs on line 35.

What i am trying to do in the issamebook function is search for the ISBN number of the book and then look at the next 2 items in the list after the ISBN number which has been found and see if they match the author and title of the book. I then am trying to reduce the stock by one as if the person has taken the book out of the library.

0

First of all, you are mixing spaces and tabs in your indentations, which will srew up most editors. Please use spaces only!

I assume the error happens in the for loop, and it looks like when you reach the integer element in your booklist you are trying to use "in" to compare a string with an integer.

Solution, have your for loop go in steps of 4 like this:
for i in range(0, len(booklist), 4):

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.