In this program, we will print numbers into words.
Steps to solve the program
- Take a number as input.
- User for loop to iterate over a number after converting it into a string using str() and create an empty string.
- Add the words with respect to the number to the empty string.
- Use if-elif statements for the purpose.
- Print the new string which contains numbers in the word form.
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)
Output :
Enter a number: 236
TwoThreeSix