Loop Programs
Python programs that practice for, while loops, and nested loops with numeric and pattern problems.
25 program solutions
Program Solutions
Print Numbers 1–100
Use a loop to print numbers from 1 to 100.
Print Even Numbers in Range
Print all even numbers between 1 and a given upper limit.
Print Odd Numbers in Range
Print all odd numbers between 1 and a given upper limit.
Sum of Digits
Compute the sum of digits of an integer using a loop.
Reverse Digits of a Number
Reverse the digits of an integer using a loop.
Calculate Factorial (Loop)
Calculate the factorial of a non-negative integer using a loop.
Fibonacci Series
Print the first N terms of the Fibonacci sequence using a loop.
Palindrome Number Check
Check whether an integer is a palindrome using digit reversal.
Count Digits in a Number
Count how many digits an integer has using a loop.
GCD of Two Numbers (Loop)
Compute the greatest common divisor (GCD) of two integers using the Euclidean algorithm.
LCM of Two Numbers (Loop)
Compute the least common multiple (LCM) of two integers using GCD.
Print Prime Numbers in Range
Print all prime numbers in a given inclusive range.
Count Prime Numbers in Range
Count how many prime numbers appear in a given inclusive range.
Check Composite Number
Check whether a number is composite (non-prime, greater than 1).
Power of 2 Checker
Check whether a positive integer is a power of 2 using a loop.
Print Number Pattern
Print a basic right-angled triangle number pattern using nested loops.
Print Star Pattern
Print a right-angled triangle star pattern using nested loops.
Armstrong Numbers in Range
Print all Armstrong numbers in a given range using loops.
Strong Numbers in Range
Print all strong numbers in a given range.
Sum of Series 1/1 + 1/2 + … + 1/N
Compute the sum of the harmonic series up to N terms.
Print Multiplication Series
Print a multiplication series for a number in a compact single-line format.
Print Pyramid Pattern
Print a centered pyramid of stars using nested loops.
Print Inverted Pyramid Pattern
Print an inverted centered pyramid of stars.
Print Floyd's Triangle
Print Floyd's triangle (consecutive numbers in a right-angled triangle).
Print Pascal's Triangle
Print Pascal's triangle up to N rows using a loop and binomial coefficients.