Print Primes Between 1-100

Print all prime numbers between 1 and 100.

Logic BuildingIntermediate
Logic Building
# Print primes from 1 to 100
print("Prime numbers from 1 to 100:")
for num in range(2, 101):
    is_prime = True
    for i in range(2, int(num ** 0.5) + 1):
        if num % i == 0:
            is_prime = False
            break
    if is_prime:
        print(num, end=" ")
print()

Output

Prime numbers from 1 to 100:
2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97

Check each number for primality.

Key Concepts:

  • Outer loop: numbers 2 to 100
  • Inner loop: check divisors up to sqrt(num)
  • If no divisor found, it's prime