In this program, we will take a string as input and convert numeric words to numbers.
Steps to solve the program
- Take a string of numeric words as input.
- Use For loop to iterate over each word of the string.
- Create an empty string.
- Convert the numeric word to its corresponding number and add it to the empty string.
- Print the output.
#Input string
string = "five four three two one"
new_str = ""
for val in string.split():
if val == "one":
new_str += "1"
elif val == "two":
new_str += "2"
elif val == "three":
new_str += "3"
elif val == "four":
new_str += "4"
elif val == "five":
new_str += "5"
elif val == "six":
new_str += "6"
elif val == "seven":
new_str += "7"
elif val == "eight":
new_str += "8"
elif val == "nine":
new_str += "9"
elif val == "ten":
new_str += "10"
#Printing output
print(new_str)
Output :
54321