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

Xiith is created for educational, experimental, and schooling purpose. Examples on Xiith are made easier to make a better or basic understanding. Tutorials, testimonials, and examples are continuously checked to avoid delusion, but we cannot take complete responsibility of all programs on Xiith. When you are operating this site, you have to agree to read and accept our terms of use, cookie and privacy policy.Copyright © 2020 by Xiith. All Rights Reserved. About us.