On 11/07/14 12:27, Avishek Mondal wrote:

     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?

Break it down. Try evaluyating

>>> min( 6+7)

You get the same ertror because Python sees that as:

>>> min(13)

And min expects a series of numbers not a single int.

Maybe you meant to use

    for i in range(1, min(n1, n2)+1):

??

Finally, don't do this:

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

Its very bad practice and a security nightmare.
A user could type any Python expression and it would be evaluated.
This could potentially result in your hard drive being formatted
or similar evils ...

To try it out (safely!) do this:

>>> value = eval(input("Type a number "))

Then at the prompt type

exit()

And hit enter and see what happens.

Use a conversion function to convert to whatever
type you want. In your case probably int()


--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.flickr.com/photos/alangauldphotos

_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

Reply via email to