Answers for "for else python example"

1

python for/else

for n in range(2, 10):
    for x in range(2, n):
        if n % x == 0:
            print( n, 'equals', x, '*', n/x)
            break
    else:
        # loop fell through without finding a factor
        print(n, 'is a prime number')
Posted by: Guest on July-22-2021
0

for-else in python

numbers = [2, 4, 6, 8, 1]
for number in numbers:    
  if number % 2 == 1:        
    print(number)        
    break
else:    
  print("No odd numbers")
Posted by: Guest on May-11-2021

Python Answers by Framework

Browse Popular Code Answers by Language