Program to convert an integer to its word format

In this python function program, we will create a function to convert an integer to its word format.

What is Function?
It is a block of code that executes when it is called.
To create a function use def keyword.

Steps to solve the program
  1. Create a function to_number.
  2. Use the def keyword to define the function.
  3. Take a number as input.
  4. User for loop to iterate over a number after converting it into a string using str() and create an empty string.
  5. Add the words with respect to the number to the empty string.
  6. Use if-elif statements for the purpose.
  7. Print the new string which contains numbers in the word form.
  8. Call the function to get the output.
				
					def to_number():
    num = int(input("Enter a number: "))
    str1 = ""

    for i in str(num):
        if i == "1":
            str1 += "One"
        elif i == "2":
            str1 += "Two"
        elif i == "3":
            str1 += "Three"
        elif i == "4":
            str1 += "Four"
        elif i == "5":
            str1 += "Five"
        elif i == "6":
            str1 += "Six"
        elif i == "7":
            str1 += "Seven"
        elif i == "8":
            str1 += "Eight"
        elif i == "9":
            str1 += "Nine"

    print(str1)
to_number()
				
			

Output :

				
					Enter a number: 2563
TwoFiveSixThree
				
			

Related Articles

get a valid mobile number.

get all permutations from a string.

Leave a Comment