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')
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')
python for else
list = [99, 98, 97, 96, 95, 94] for number in list: if number == 2: print("There is a 2 in the list") break else: print("There are no 2's in the list") # The else statement is only reached if the for loop # has run all the way through without breaking
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")
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us