-
Notifications
You must be signed in to change notification settings - Fork 0
Open
@hug2wisdom
Description
for n in range(2, 10):
for x in range(2, n):
if n % x == 0:
print(n, 'equals', x, '*', n // x)
break
else:
print(n, 'is a prime number')
(Yes, this is the correct code. Look closely: the else clause belongs to the for loop, not the if statement.)
else 不仅仅可以与 if 连在一起使用,还可以与 for,try,while 使用。
Metadata
Metadata
Assignees
Labels
No labels