INTRODUCTION
πΉ 1) Concept of Digit Extraction using Modulo and Division
These programs are based on number manipulation techniques in Python using:
-
%(modulus operator) β gives remainder -
//(floor division) β removes digits from a number
π Example:
-
1234 % 100 = 34β last 2 digits -
1234 // 100 = 12β first 2 digits
This concept is used to split numbers into parts without converting them into strings.
πΉ 2) Concept of While Loop in Number Processing
All programs use a while loop, which is used when the number of iterations is not fixed.
Structure:
while condition:
statements
Purpose in these tasks:
- Repeatedly extract digits
- Reduce the number step-by-step
- Stop when number becomes 0 or condition fails
πΉ 3) Concept of Pattern Formation in Numbers
These tasks are based on creating patterns like:
Examples:
1234 β 34 23 121234 β 34 12123456 β 456 123
This is done by:
- Changing how many digits are removed each time (
// 10,// 100,// 1000) - Controlling overlapping or non-overlapping digit groups
πΉ 4) Concept of Sum of Extracted Values
In sum-based tasks:
Idea:
Instead of printing values, we accumulate them in a variable
sum = sum + extracted_value
Working:
- Extract number using
% - Add it to sum
- Reduce number using
//
πΉ 5) Concept of Product of Extracted Values
Same logic as sum, but using multiplication:
Idea:
product = product * extracted_value
Important:
- Initial value must be 1
- Used for cumulative multiplication of extracted digits
πΉ 6) Concept of Overlapping vs Non-Overlapping Extraction
πΈ Overlapping extraction:
Uses // 10
Example:
1234 β 34 β 23 β 12
π digits overlap
πΈ Non-overlapping extraction:
Uses // 100 or // 1000
Example:
1234 β 34 β 12
π digits do NOT overlap
πΉ 7) Concept of Splitting Large Numbers
Example:
123456 β 456 123
Logic:
-
% 1000β last 3 digits -
// 1000β first 3 digits
This is useful in:
- ID processing
- roll numbers
- data segmentation
Task-1 : Print 34 23 12
Concept
The program extracts and prints the last two digits of a number using the modulo operator (% 100). After printing, it removes only the last digit using integer division (// 10). This creates overlapping two-digit groups.
-
no % 100prints the last two digits. -
no // 10removes only the last digit, allowing the next overlapping pair to be formed.
For 1234:
- First iteration β 34
- Second iteration β 23
- Third iteration β 12
Algorithm
- Start.
- Assign
no = 1234. - Check whether
no >= 10. - If true:
- Print
no % 100. - Update
no = no // 10.- Repeat Step 3 until
no < 10. - Stop.
- Repeat Step 3 until
Flowchart
βββββββββ
β Start β
βββββ¬ββββ
β
βΌ
ββββββββββββ
β no=1234 β
ββββββ¬ββββββ
β
βΌ
ββββββββββββ
β no >= 10 ββββββββ
βββββ¬βββββββ β
Yes No
β β
βΌ βΌ
ββββββββββββββ ββββββββ
βPrint no%100β β Stop β
βββββββ¬βββββββ ββββββββ
β
βΌ
βββββββββββββ
βno=no//10 β
βββββββ¬ββββββ
β
ββββββββββββΊ Back to Condition
Program
no = 1234
while no >= 10:
print(no % 100,end=" ")
no = no // 10
π Execution Table
| Iteration [3, 4, 5, 6, 7] | Loop Condition (no >= 10) | Execution Step | Operation | Result / Output |
|---|---|---|---|---|
| Start | Initial Value | Set starting number | no = 1234 | no is 1234 |
| Loop 1 | 1234 >= 10 (True) | 1. Print statement | 1234 % 100 | Prints 34 |
| 2. Floor division | 1234 // 10 | no becomes 123 | ||
| Loop 2 | 123 >= 10 (True) | 1. Print statement | 123 % 100 | Prints 23 |
| 2. Floor division | 123 // 10 | no becomes 12 | ||
| Loop 3 | 12 >= 10 (True) | 1. Print statement | 12 % 100 | Prints 12 |
| 2. Floor division | 12 // 10 | no becomes 1 | ||
| End | 1 >= 10 (False) | Loop terminates | Exit loop | Program finishes successfully |
Trace Table
| Iteration | no (Before) | no % 100 | Output | no = no // 10 |
|---|---|---|---|---|
| 1 | 1234 | 34 | 34 | 123 |
| 2 | 123 | 23 | 23 | 12 |
| 3 | 12 | 12 | 12 | 1 |
Output
Task-2 : Print 34 12
Concept
This program extracts and prints the last two digits of a number repeatedly using the modulo operator (% 100). After printing, it removes the last two digits using integer division (// 100). The process continues until the number becomes 0.
For 1234:
- First iteration β 34
Second iteration β 12
no%100) #prints 34 by 1234/100 = 34 remainder from 12.34
no//100 #prints 12 by 1234//100 = 12 quotient, 34 is rem, avoids it
Algorithm
- Start.
- Assign
no = 1234. - Check whether
no > 0. - If true:
- Print
no % 100. - Update
no = no // 100.- Repeat Step 3 until
no = 0. - Stop.
- Repeat Step 3 until
Flowchart
βββββββββ
β Start β
βββββ¬ββββ
β
βΌ
ββββββββββββ
β no=1234 β
ββββββ¬ββββββ
β
βΌ
ββββββββββββ
β no > 0 ββββββββ
βββββ¬βββββββ β
Yes No
β β
βΌ βΌ
ββββββββββββββ ββββββββ
βPrint no%100β β Stop β
βββββββ¬βββββββ ββββββββ
β
βΌ
βββββββββββββ
βno=no//100 β
βββββββ¬ββββββ
β
ββββββββββββΊ Back to Condition
Program
no = 1234
while no > 0:
print(no % 100,end=" ")
no = no // 100
π Execution Table
| Iteration [3, 4, 5, 6, 7] | Loop Condition (no > 0) | Execution Step | Operation | Result / Output |
|---|---|---|---|---|
| Start | Initial Value | Set starting number | no = 1234 | no is 1234 |
| Loop 1 | 1234 > 0 (True) | 1. Print statement | 1234 % 100 | Prints 34 (Last 2 digits) |
| 2. Floor division | 1234 // 100 | no becomes 12 (removes last 2 digits) | ||
| Loop 2 | 12 > 0 (True) | 1. Print statement | 12 % 100 | Prints 12 (Remaining digits) |
| 2. Floor division | 12 // 100 | no becomes 0 | ||
| End | 0 > 0 (False) | Loop terminates | Exit loop | Program finishes successfully |
Trace Table
| Iteration | no (Before) | no % 100 | Output | no = no // 100 |
|---|---|---|---|---|
| 1 | 1234 | 34 | 34 | 12 |
| 2 | 12 | 12 | 12 | 0 |
Output
Task-3 : Sum of task 1 (34 23 12)
Concept
This program extracts overlapping two-digit numbers from 1234 using the modulo operator (% 100) and adds them. After each extraction, it removes only the last digit using integer division (// 10).
For 1234:
- First iteration β 34
- Second iteration β 23
- Third iteration β 12
Sum = 34 + 23 + 12 = 69
-
no % 100extracts the last two digits. -
no // 10removes only the last digit. -
sum = sum + (no % 100)adds each extracted value to the total.
Algorithm
- Start.
- Assign
no = 1234andsum = 0. - Check whether
no >= 10. - If true:
- Add
no % 100tosum. - Update
no = no // 10.- Repeat Step 3 until
no < 10. - Print
sum. - Stop.
- Repeat Step 3 until
Flowchart
βββββββββ
β Start β
βββββ¬ββββ
β
βΌ
ββββββββββββββββββ
β no=1234,sum=0 β
βββββββββ¬βββββββββ
β
βΌ
ββββββββββββ
β no >= 10 ββββββββ
βββββ¬βββββββ β
Yes No
β β
βΌ βΌ
ββββββββββββββββββ ββββββββββββ
βsum=sum+no%100 β βPrint sum β
βββββββββ¬βββββββββ ββββββ¬ββββββ
β β
βΌ βΌ
βββββββββββββ ββββββββ
βno=no//10 β β Stop β
βββββββ¬ββββββ ββββββββ
β
ββββββββββββΊ Back to Condition
Program
no = 1234
sum = 0
while no >= 10:
sum = sum + (no % 100)
no = no // 10
print(sum)
π Execution Table
| Iteration | Loop Condition (no >= 10) | Operation | Calculation | Sum |
|---|---|---|---|---|
| Start | Initial Value | sum = 0 | - | 0 |
| Loop 1 | 1234 >= 10 (True) | sum = sum + (1234 % 100) | 0 + 34 | 34 |
| no = 1234 // 10 | no = 123 | |||
| Loop 2 | 123 >= 10 (True) | sum = sum + (123 % 100) | 34 + 23 | 57 |
| no = 123 // 10 | no = 12 | |||
| Loop 3 | 12 >= 10 (True) | sum = sum + (12 % 100) | 57 + 12 | 69 |
| no = 12 // 10 | no = 1 | |||
| End | 1 >= 10 (False) | Loop terminates | Exit loop | 69 |
Trace Table
| Iteration | no (Before) | no % 100 | Sum After Addition | no = no // 10 |
|---|---|---|---|---|
| 1 | 1234 | 34 | 34 | 123 |
| 2 | 123 | 23 | 57 | 12 |
| 3 | 12 | 12 | 69 | 1 |
Output
Task-4 : Sum of task 2 (34 12)
Concept
This program extracts and adds the last two digits of a number repeatedly using the modulo operator (% 100). After each extraction, it removes the last two digits using integer division (// 100).
For 1234:
- First iteration β 34
- Second iteration β 12
Sum = 34 + 12 = 46
-
no % 100extracts the last two digits. -
no // 100removes the last two digits. -
sum = sum + (no % 100)adds each extracted value to the total.
Algorithm
- Start.
- Assign
no = 1234andsum = 0. - Check whether
no > 0. - If true:
- Add
no % 100tosum. - Update
no = no // 100.- Repeat Step 3 until
no = 0. - Print
sum. - Stop.
- Repeat Step 3 until
Flowchart
βββββββββ
β Start β
βββββ¬ββββ
β
βΌ
ββββββββββββββββββ
β no=1234,sum=0 β
βββββββββ¬βββββββββ
β
βΌ
ββββββββββββ
β no > 0 ββββββββ
βββββ¬βββββββ β
Yes No
β β
βΌ βΌ
ββββββββββββββββββ ββββββββββββ
βsum=sum+no%100 β βPrint sum β
βββββββββ¬βββββββββ ββββββ¬ββββββ
β β
βΌ βΌ
βββββββββββββ ββββββββ
βno=no//100 β β Stop β
βββββββ¬ββββββ ββββββββ
β
ββββββββββββΊ Back to Condition
Program
no = 1234
sum = 0
while no > 0:
sum = sum + (no % 100)
no = no // 100
print(sum)
π Execution Table
| Iteration | Loop Condition (no > 0) | Operation | Calculation | Sum |
|---|---|---|---|---|
| Start | Initial Value | sum = 0 | - | 0 |
| Loop 1 | 1234 > 0 (True) | sum = sum + (1234 % 100) | 0 + 34 | 34 |
| no = 1234 // 100 | no = 12 | |||
| Loop 2 | 12 > 0 (True) | sum = sum + (12 % 100) | 34 + 12 | 46 |
| no = 12 // 100 | no = 0 | |||
| End | 0 > 0 (False) | Loop terminates | Exit loop | 46 |
Trace Table
| Iteration | no (Before) | no % 100 | Sum After Addition | no = no // 100 |
|---|---|---|---|---|
| 1 | 1234 | 34 | 34 | 12 |
| 2 | 12 | 12 | 46 | 0 |
Output
Task-5 : Product of task 1 (34 23 12)
Concept
This program extracts overlapping two-digit numbers from 1234 using the modulo operator (% 100) and multiplies them. After each extraction, it removes only the last digit using integer division (// 10).
For 1234:
- First iteration β 34
- Second iteration β 23
- Third iteration β 12
Product = 34 Γ 23 Γ 12 = 9384
-
no % 100extracts the last two digits. -
no // 10removes only the last digit. -
product = product * (no % 100)multiplies each extracted value.
Algorithm
- Start.
- Assign
no = 1234andproduct = 1. - Check whether
no >= 10. - If true:
- Multiply
productwithno % 100. - Update
no = no // 10.- Repeat Step 3 until
no < 10. - Print
product. - Stop.
- Repeat Step 3 until
Flowchart
βββββββββ
β Start β
βββββ¬ββββ
β
βΌ
ββββββββββββββββββββββ
β no=1234, product=1 β
ββββββββββ¬ββββββββββββ
β
βΌ
ββββββββββββ
β no >= 10 ββββββββ
βββββ¬βββββββ β
Yes No
β β
βΌ βΌ
ββββββββββββββββββββββ ββββββββββββββ
βproduct=product*%100β βPrint productβ
βββββββββ¬βββββββββββββ ββββββ¬ββββββββ
β β
βΌ βΌ
βββββββββββββ ββββββββ
βno=no//10 β β Stop β
βββββββ¬ββββββ ββββββββ
β
ββββββββββββΊ Back to Condition
Program
no = 1234
product = 1
while no >= 10:
product = product * (no % 100)
no = no // 10
print(product)
π Execution Table
| Iteration | Loop Condition (no >= 10) | Operation | Calculation | Product |
|---|---|---|---|---|
| Start | Initial Value | product = 1 | - | 1 |
| Loop 1 | 1234 >= 10 (True) | product = product Γ (1234 % 100) | 1 Γ 34 | 34 |
| no = 1234 // 10 | no = 123 | |||
| Loop 2 | 123 >= 10 (True) | product = 34 Γ (123 % 100) | 34 Γ 23 | 782 |
| no = 123 // 10 | no = 12 | |||
| Loop 3 | 12 >= 10 (True) | product = 782 Γ (12 % 100) | 782 Γ 12 | 9384 |
| no = 12 // 10 | no = 1 | |||
| End | 1 >= 10 (False) | Loop terminates | Exit loop | 9384 |
Trace Table
| Iteration | no (Before) | no % 100 | Product After Multiplication | no = no // 10 |
|---|---|---|---|---|
| 1 | 1234 | 34 | 34 | 123 |
| 2 | 123 | 23 | 782 | 12 |
| 3 | 12 | 12 | 9384 | 1 |
Output
Task-6 : Product of task 2 (34 12)
Concept
This program extracts the last two digits of a number repeatedly using the modulo operator (% 100) and multiplies them. After each extraction, it removes the last two digits using integer division (// 100).
For 1234:
- First iteration β 34
- Second iteration β 12
Product = 34 Γ 12 = 408
-
no % 100extracts the last two digits. -
no // 100removes the last two digits. -
product = product * (no % 100)multiplies each extracted value.
Algorithm
- Start.
- Assign
no = 1234andproduct = 1. - Check whether
no > 0. - If true:
- Multiply
productwithno % 100. - Update
no = no // 100.- Repeat Step 3 until
no = 0. - Print
product. - Stop.
- Repeat Step 3 until
Flowchart
βββββββββ
β Start β
βββββ¬ββββ
β
βΌ
ββββββββββββββββββββββ
β no=1234,product=1 β
ββββββββββ¬ββββββββββββ
β
βΌ
ββββββββββββ
β no > 0 ββββββββ
βββββ¬βββββββ β
Yes No
β β
βΌ βΌ
ββββββββββββββββββββββ ββββββββββββββ
βproduct=product*%100β βPrint productβ
βββββββββ¬βββββββββββββ ββββββ¬ββββββββ
β β
βΌ βΌ
βββββββββββββ ββββββββ
βno=no//100 β β Stop β
βββββββ¬ββββββ ββββββββ
β
ββββββββββββΊ Back to Condition
Program
no = 1234
product = 1
while no > 0:
product = product * (no % 100)
no = no // 100
print(product)
π Execution Table
| Iteration | Loop Condition (no > 0) | Operation | Calculation | Product |
|---|---|---|---|---|
| Start | Initial Value | product = 1 | - | 1 |
| Loop 1 | 1234 > 0 (True) | product = 1 Γ (1234 % 100) | 1 Γ 34 | 34 |
| no = 1234 // 100 | no = 12 | |||
| Loop 2 | 12 > 0 (True) | product = 34 Γ (12 % 100) | 34 Γ 12 | 408 |
| no = 12 // 100 | no = 0 | |||
| End | 0 > 0 (False) | Loop terminates | Exit loop | 408 |
Trace Table
| Iteration | no (Before) | no % 100 | Product After Multiplication | no = no // 100 |
|---|---|---|---|---|
| 1 | 1234 | 34 | 34 | 12 |
| 2 | 12 | 12 | 408 | 0 |
Output
Task-7 : 123456 β Print 456 123
Concept
This program splits a 6-digit number into two parts using:
-
% 1000β gives last 3 digits -
// 1000β gives first 3 digits
It prints both values in a loop style similar to the previous tasks.
For 123456:
- First iteration β 456
- Second iteration β 123
Algorithm
- Start.
- Assign
no = 123456. - Check whether
no > 0. - If true:
- Print
no % 1000. - Update
no = no // 1000.- Repeat until
no = 0. - Stop.
- Repeat until
Flowchart
βββββββββ
β Start β
βββββ¬ββββ
β
βΌ
ββββββββββββββββ
β no = 123456 β
ββββββ¬ββββββββββ
β
βΌ
ββββββββββββ
β no > 0 ββββββββ
βββββ¬βββββββ β
Yes No
β β
βΌ βΌ
ββββββββββββββββββ ββββββββ
βPrint no % 1000 β β Stop β
βββββββ¬βββββββββββ ββββββββ
β
βΌ
ββββββββββββββββ
β no = no//1000β
βββββββ¬βββββββββ
β
ββββββββββββΊ Back to Condition
Program
no = 123456
while no > 0:
print(no % 1000, end=" ")
no = no // 1000
π Execution Table
| Iteration | no (Before) | no % 1000 | Output | no = no // 1000 |
|---|---|---|---|---|
| 1 | 123456 | 456 | 456 | 123 |
| 2 | 123 | 123 | 123 | 0 |
Trace Table
| Iteration | no (Before) | no % 1000 | Output |
|---|---|---|---|
| 1 | 123456 | 456 | 456 |
| 2 | 123 | 123 | 123 |
Output
π Number Manipulation Tasks
| Task No | Input Number | Operation | Concept Used | Method | Output |
|---|---|---|---|---|---|
| 1 | 1234 | Print 34 23 12 | Overlapping digit extraction |
% 100 + // 10 in while loop |
34 23 12 |
| 2 | 1234 | Print 34 12 | Non-overlapping digit extraction |
% 100 + // 100 in while loop |
34 12 |
| 3 | 1234 | Sum of Task 1 values | Accumulation (Sum) | sum = sum + value |
69 |
| 4 | 1234 | Sum of Task 2 values | Accumulation (Sum) | sum = sum + value |
46 |
| 5 | 1234 | Product of Task 1 values | Accumulation (Product) | product = product * value |
9384 |
| 6 | 1234 | Product of Task 2 values | Accumulation (Product) | product = product * value |
408 |
| 7 | 123456 | Print 456 123 | Number splitting |
% 1000 + // 1000
|
456 123 |
π Summary
-
%β extracts last digits -
//β removes last digits -
while loopβ repeated digit processing - Overlapping extraction β
// 10 - Non-overlapping extraction β
// 100or// 1000 - Sum logic β
sum = sum + value - Product logic β
product = product * value - Number splitting β large number separation
- %100 --> gives last two digits
- //100 --> removes last two digits
- Additive Identity 0
- Multiplicative identity 1
- Floor division operator (//) calculates the integer quotient by rounding down to the nearest whole number
- Modulo operator (%) calculates the remainder left over from that division.
Overall Learning Outcome
From these programs, we learn:
β How to extract digits without strings
β How loops control number processing
β How arithmetic operators manipulate data
β How patterns are formed from numbers
β Difference between sum and product accumulation
β Real-world use of digit splitting logic







Top comments (0)