for with else : For « Language Basics « Python






for with else

for with else

from math import sqrt
for n in range(99, 82, -1):
    root = sqrt(n)
    if root == int(root):
        print n
        break
else:
    print "Didn't find it!"

           
       








Related examples in the same category

1.Dictionary for loopDictionary for loop
2.For loop demoFor loop demo
3.Nested if demoNested if demo
4.Calculating compound interest.Calculating compound interest.