Introduction to While Loops
While Loops
# While Loop Format
while __boolean_condition__:
your code here
# end of while loopExample: Printing Factors of a Number
# Example Program 1:
# Factors of a Number
num = 12
divisor = 1
while divisor <= num:
if num % divisor == 0:
print(divisor, 'is a factor of', num)
divisor += 1
# end of while1 is a factor of 12
2 is a factor of 12
3 is a factor of 12
4 is a factor of 12
6 is a factor of 12
12 is a factor of 12Python Specific: While … Else Structure
Last updated