Growing Reverse Number Pattern in Python

Beginner
⏱️ 6 min read
📚 Updated: Aug 2025
🎯 2 Code Examples
Modulo + Division

What You’ll Learn

How to print a growing reverse number pattern in Python. Starting from the last digit, we build the reversed number step-by-step and print it at each step.

This pattern is a practical way to understand digit extraction using % 10 and digit removal using // 10.

⭐ Pattern Output

For num = 86523, the pattern looks like this:

Output
3
32
325
3256
32568
1

Complete Python Program

Extract the last digit, append it to reverse, print it, and then remove the digit from num.

Python
num = 86523
reverse = 0

while num != 0:
    reverse = reverse * 10 + (num % 10)
    print(reverse)
    num //= 10

🧠 How It Works

1

Initialize variables

num holds the remaining digits, and reverse stores the growing reverse value.

Setup
2

Extract the last digit

num % 10 gives the last digit of the current number.

Digit
3

Append digit to reverse

reverse = reverse * 10 + digit shifts existing digits left and adds the new digit.

Build
4

Remove the last digit

num //= 10 discards the last digit so we can process the next one.

Shrink
=

Growing reverse

Each iteration adds one digit, so the loop runs once per digit (\(O(d)\)).

2

Variation — User Input Version

Let the user enter a number and print the same growing reverse pattern.

Python
num = int(input("Enter a number: "))
num = abs(num)

reverse = 0

if num == 0:
    print(0)
else:
    while num != 0:
        reverse = reverse * 10 + (num % 10)
        print(reverse)
        num //= 10

💡 Tips for Enhancement

Try These

  • Skip printing leading zeros by ignoring digits until the first non-zero digit
  • Print both digit and reverse each step for learning
  • Use this technique to reverse a number completely
  • Try building the pattern as strings instead of integers
  • Handle very large integers (Python supports big ints by default)

Avoid

  • Using floating-point division (always use //)
  • Forgetting to update num (infinite loop)
  • Assuming input is always positive without handling negatives
  • Confusing this pattern with printing suffixes (this prints reverse prefixes)

Key Takeaways

1

% 10 extracts the last digit; // 10 removes it.

2

reverse = reverse * 10 + digit appends a digit to the right.

3

Printing reverse each step produces the growing pattern.

4

Work is proportional to digits, so it’s O(d).

❓ Frequently Asked Questions

Because we extract digits using num % 10, which reads the number from right to left.
You can skip printing until you hit the first non-zero digit, or treat the number as a string and trim trailing zeros first.
It uses the same technique, but we print intermediate reverse values after each digit is appended.
O(d), where d is the number of digits.

Explore More Python Number Patterns!

Once you understand digit extraction, try sum-of-digits, reverse, and palindrome challenges.

All Number Patterns →
Did you know?

Building a reverse number uses the same core idea as converting digits into a number in base-10: multiply by 10, then add the next digit.

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

7 people found this page helpful