Phase 2 - Level 2: Number-based Looping Logic
Apply loops to solve number manipulation problems.
14 programs · open one, then the next
Start with Count Digits in a Number- 01Count Digits in a NumberIntermediateCount decimal digits in an integer by repeatedly dividing by ten. Students trace a Python while loop, ignore a negative sign, and handle zero as one digit.Open example →py# Take number num = int(input("Enter a number: ")) # Count digits
- 02Reverse a NumberIntermediateReverse an integer with arithmetic rather than slicing text. Students trace place-value rebuilding, negative-sign restoration, and the loss of trailing zeros.Open example →py# Take number num = int(input("Enter a number: ")) # Reverse number
- 03Check Palindrome NumberIntermediateCheck an integer palindrome with a digit-reversal loop. Students preserve the original magnitude, build its reverse, and compare numeric values after the loop.Open example →py# Take number num = int(input("Enter a number: ")) # Reverse number
- 04Sum of DigitsIntermediateAdd the decimal digits of an integer with Python modulo and floor division. Students follow a running total, a shrinking copy, and sign-independent digit sums.Open example →py# Take number num = int(input("Enter a number: ")) # Sum of digits
- 05Armstrong Number CheckIntermediateCheck Armstrong numbers using the number of digits as the power. Students trace two Python digit loops and distinguish exponentiation from bitwise XOR.Open example →py# Take number num = int(input("Enter a number: ")) # Count digits
- 06Perfect Number CheckIntermediateTest whether a positive integer equals its proper-divisor sum. A lesson on excluding the number itself, accumulating factors, and perfect-number boundaries.Open example →py# Take number num = int(input("Enter a number: ")) # Find sum of proper divisors
- 07Print Primes Between 1-100IntermediateList primes from two through one hundred with nested loops. Students trace a fresh candidate flag, square-root bounds, and early exit after finding a factor.Open example →py# Print primes from 1 to 100 print("Prime numbers from 1 to 100:") for num in range(2, 101): is_prime = True
- 08Check if Number is PrimeIntermediateDetermine whether one integer is prime with Python. Students reject numbers below two and trace trial division, a flag, and the square-root stopping bound.Open example →py# Take number num = int(input("Enter a number: ")) # Check prime
- 09Fibonacci Series Up to NIntermediatePrint a number of Fibonacci terms with Python. Students handle short sequences first, update two previous terms, and separate a term count from a value limit.Open example →py# Take n n = int(input("Enter number of terms: ")) # Generate Fibonacci
- 10Sum of First N Fibonacci TermsIntermediateAdd the first n Fibonacci terms without storing a list. Students trace the starting pair, a running total, and the difference between terms and their sum.Open example →py# Take n n = int(input("Enter n: ")) # Calculate sum
- 11Product of Digits with an Explicit Zero CaseIntermediateCalculate digit products with an explicit zero branch. Students contrast empty-loop behavior with a valid zero result while preserving negative-input handling.Open example →py# Take number num = int(input("Enter a number: ")) # Calculate product
- 12Strong Number Check with Recursive FactorialsIntermediateRecognize strong numbers with a recursive factorial helper. Students trace digit factorials, recursion's base case, and the positive-input check for zero.Open example →py# Helper function for factorial def factorial(n): if n == 0 or n == 1: return 1
- 13Harshad Number CheckIntermediateCheck divisibility by a number's digit sum with Python. Students trace Harshad logic, absolute values, and a guard that prevents a zero-divisor error.Open example →py# Take number num = int(input("Enter a number: ")) # Calculate sum of digits
- 14Abundant Number CheckIntermediateFind whether proper divisors sum to more than a positive integer. Students use a factor loop to distinguish abundant numbers from perfect and deficient ones.Open example →py# Take number num = int(input("Enter a number: ")) # Find sum of proper divisors