Phase 2 - Level 5: Logical Loop Combinations
Combine loops with complex logic - filtering, conditional accumulation.
12 programs · open one, then the next
Start with Numbers with Even Digit Sum- 01Numbers with Even Digit SumAdvancedFilter one through one hundred by an even digit sum with Python. Students combine an outer candidate loop, an inner digit loop, and a final remainder test.Open example →py# Print numbers with even digit sum print("Numbers 1-100 with even digit sum:") for num in range(1, 101): # Calculate digit sum
- 02Count Numbers Divisible by 7 but Not 5AdvancedCount integers up to five hundred divisible by seven but not five. Students use and with a negated divisibility test and count matches rather than sum them.Open example →py# Count numbers count = 0 for num in range(1, 501): if num % 7 == 0 and num % 5 != 0:
- 03All Palindrome Numbers 1-500AdvancedFind every numeric palindrome from one through five hundred. Students rebuild each candidate's reverse and reset temporary values within the outer loop.Open example →py# Print palindrome numbers print("Palindrome numbers 1-500:") for num in range(1, 501): # Reverse number
- 04Numbers with Digit Sum Multiple of 3AdvancedSelect numbers with digit sums divisible by three using Python. Students trace nested loops and compare a digit-based rule with direct number divisibility.Open example →py# Print numbers print("Numbers with digit sum multiple of 3:") for num in range(1, 101): # Calculate digit sum
- 05Smallest & Largest DigitAdvancedTrack the smallest and largest digits with Python. Students update two running extremes, handle negative magnitudes, and treat zero as a real digit.Open example →py# Take number num = int(input("Enter a number: ")) # Find smallest and largest digit
- 06Numbers with Even 1s in BinaryAdvancedPrint numbers whose binary form has an even count of ones. Students use Python bin, slicing, count, and a parity test that differs from even-number testing.Open example →py# Print numbers print("Numbers with even 1s in binary:") for num in range(1, 21): # Count 1s in binary
- 07Print i*i PatternAdvancedPrint a row of integer squares using Python. Students trace a one-line sequence, multiplication before output, and a newline separate from the number loop.Open example →py# Take n n = int(input("Enter n: ")) # Print i*i pattern
- 08Factorial of Each Number 1-NAdvancedCalculate and print a factorial for every integer through n. Students trace Python nested loops and reset each inner product before multiplying its factors.Open example →py# Take n n = int(input("Enter n: ")) # Print factorials
- 09Sum of Odd & Even Digits SeparatelyAdvancedAdd odd digits and even digits into separate totals with Python. Students classify each extracted digit by parity rather than by its position in the number.Open example →py# Take number num = int(input("Enter a number: ")) # Sum odd and even digits
- 10Sum with Continue (Skip 0)AdvancedRead five integers and skip zero values with continue in Python. Students distinguish ending one iteration from ending a loop and trace a running input total.Open example →py# Take 5 numbers sum = 0 for i in range(5): num = int(input(f"Enter number {i+1}: "))
- 11Sum of Squares of Even NumbersAdvancedSum squares of even numbers through a limit with Python. Students select terms with a stepped range, square each value, and build the running total.Open example →py# Take n n = int(input("Enter n: ")) # Sum squares of evens
- 12Count Primes in RangeAdvancedCount primes in an inclusive interval with nested loops. Students skip candidates below two, stop factor checks early, and increment a count only for primes.Open example →py# Take range a = int(input("Enter start: ")) b = int(input("Enter end: "))