[Tutor] TypeError: 'int' object is not iterable

Avishek Mondal mondal.avishekri at yahoo.com.sg
Fri Jul 11 13:27:18 CEST 2014


Hi,

I wrote a simple program, as follows-
def finddivisor(n1, n2):
    divisor = ()
    
    for i in range(1, min(n1+n2)+1):
        if n1%i == 0 and n2%i==0:
            divisor = divisor + (i, )
    return divisor

n1 = eval(input('Enter first number: '))
n2 = eval(input('Enter second number: '))


divisors= finddivisor(n1,n2)
print (divisors)

However, when I run it, the message

Traceback (most recent call last):
  File "C:/Python33/Trials/tuple trial.py", line 21, in <module>
    divisors= finddivisor(n1,n2)
  File "C:/Python33/Trials/tuple trial.py", line 12, in finddivisor
    for i in range(1, min(n1+n2)+1):
TypeError: 'int' object is not iterable

shows up. Could you please tell me where I went wrong? Does it mean that if i in an integer, it will not be iterated? But isn't the code for i in range(1, n) a very frequently used line?

Thank you for your help!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20140711/dbc89a29/attachment.html>


More information about the Tutor mailing list