BASIC FOR LOOPS
BASIC WHILE LOOPS
ACCUMULATORS
BREAK AND CONTINUE
NESTED LOOPS (CHALLENGE)
100

Write a code using for loop that prints numbers from 1 to 5.

for i in range(1, 6):
    print(i)

100

Write a code using while loop that prints numbers from 1 to 5.

x = 1
while x <= 5:
    print(x)
    x += 1

100

Write a program using a for loop to find the sum of numbers from 1 to 5.

total = 0
for i in range(1, 6):
    total += i
print(total)

100

Write a loop that prints numbers from 1 to 10 but stops when it reaches 6.

for i in range(1, 11):
    if i == 6:
        break
    print(i)

100

Write a nested loop that prints this pattern:

*
**
***

for i in range(1, 4):
    for j in range(i):
        print("*", end="")
    print()

200

Write a code using for loop that prints even numbers from 2 to 10.

for i in range(2, 11, 2):
    print(i)

200

Write a code using while loop that prints numbers from 5 down to 1.

x = 5
while x >= 1:
    print(x)
    x -= 1

200

Write a program to find the sum of even numbers from 2 to 10.

total = 0
for i in range(2, 11, 2):
    total += i
print(total)

200

Write a loop that prints numbers from 1 to 10 but skips number 5.

for i in range(1, 11):
    if i == 5:
        continue
    print(i)

200

Write a nested loop that prints numbers:

1 1
2 2
3 3

for i in range(1, 4):
    for j in range(2):
        print(i, end=" ")
    print()

300

Write a code using for loop that prints numbers from 10 down to 1.

for i in range(10, 0, -1):
    print(i)

300

Write a code using while loop that prints even numbers from 2 to 10.

x = 2
while x <= 10:
    print(x)
    x += 2

300

Write a program using while loop to find the sum of numbers from 1 to 10.

total = 0
x = 1
while x <= 10:
    total += x
    x += 1
print(total)

300

Write a while loop that stops when the user enters 0.

num = int(input("Enter number (0 to stop): "))
while num != 0:
    print("You entered:", num)
    num = int(input("Enter number (0 to stop): "))

300

Print a 3x3 grid of zeros.

for i in range(3):
    for j in range(3):
        print(0, end=" ")
    print()

400

Write a code using for loop that prints the word "Python" 4 times.

for i in range(4):
    print("Python")

400

Write a code using while loop that prints "Loop" 3 times.

x = 1
while x <= 3:
    print("Loop")
    x += 1

400

Write a program to multiply numbers from 1 to 5 (find the product).

product = 1
for i in range(1, 6):
    product *= i
print(product)

400

Write a loop that prints numbers from 1 to 20 but skips multiples of 4.

for i in range(1, 21):
    if i % 4 == 0:
        continue
    print(i)

400

Print this pattern:

1
12
123
1234

for i in range(1, 5):
    for j in range(1, i + 1):
        print(j, end="")
    print()

500

Write a code using for loop that prints all odd numbers from 1 to 15.

for i in range(1, 16, 2):
    print(i)

500

Write a code using while loop that prints multiples of 3 from 3 to 30.

x = 3
while x <= 30:
    print(x)
    x += 3

500

Write a program that asks the user for 5 numbers and prints the total.

total = 0
for i in range(5):
    num = int(input("Enter a number: "))
    total += num
print("Total:", total)

500

Write a loop that prints numbers from 1 to 20 but stops if the number is divisible by 7.

for i in range(1, 21):
    if i % 7 == 0:
        break
    print(i)

500

Print a multiplication table from 1 to 5.

for i in range(1, 6):
    for j in range(1, 6):
        print(i * j, end="\t")
    print()

M
e
n
u