Skip to content
Programs · Program 6-11

Q.Program 6-11: Program to find the factors of a whole number using while loop.

Odisha ChseTextbookSubjective· 3mImportance★★★★★est
38% · 15/39 Questions
🔒 Locked · start free trial →

You're viewing a preview — the full solution, concept, methods & PYQ mapping are locked.

Start your 14-day free trial to unlock the full solution →

A while loop drives a trial divisor factor from 1 up to the number itself; every value with num % factor == 0 is a factor — for input 12 the program prints 1 2 3 4 6 12.

The idea. A factor of a whole number is any value that divides it leaving remainder 0. The direct algorithm is trial division: test every candidate from 1 to the number. A while loop with an explicitly managed counter (factor) implements this, with the modulus operator doing the divisibility test.

# Program 6-11: find the factors of a whole number using a while loop
num = int(input("Enter a whole number: "))
factor = 1
print("Factors of", num, "are:")
while factor <= num:
    if num % factor == 0:
        print(factor, end=" ")
    factor += 1

Sample run (user enters 12)

Enter a whole number: 12
Factors of 12 are:
1 2 3 4 6 12

Dry run for num = 12 (only the interesting columns)

factor12 % factorFactor?
10yes → print 1
20yes → print 2
30yes → print 3
40yes → print 4
52no
60yes → print 6
7…11non-zerono
120yes → print 12

Unlock everything free for 14 days

  • Full step-by-step solutions
  • Concept-first explanations
  • Methods, shortcuts & mistakes
  • PYQ mapping + timed mock tests

Full access for 14 days. No credit card required.