Python Program to convert a number into characters


In this program, You will learn how to convert a number into characters in Python.


2408 => Two Four Zero Eight

Example: How to convert a number into characters in Python.

n = int(input("Enter a number:"))
rev = 0

while n > 0:
    r = n % 10
    rev = rev * 10 + r
    n = int(n / 10)

n = rev
while n > 0:
    r = n % 10
    if r == 1:
        print("One")

    if r == 2:
        print("Two")

    if r == 3:
        print("Three")

    if r == 4:
        print("Four")

    if r == 5:
        print("Five")

    if r == 6:
        print("Six")

    if r == 7:
        print("Seven")

    if r == 8:
        print("Eight")

    if r == 9:
        print("Nine")

    if r == 0:
        print("Zero")

    n = int(n / 10)

Output:

Enter a number:4503
Four
Five
Zero
Three