if the character is a numeric digit, prints its name in text (e.g., if input is 9, output is NINE)
Question:
enter image description here
in the image please see the option c . I need a program in python.
I was trying to print number in word but I didn’t get successful. I want a answer in python.
Answers:
def int_to_word(character):
character = str(character) if type(character)!=str else None
conversion_dict = {
'1': 'ONE',
'2': 'TWO',
'3': 'THREE',
'4': 'FOUR',
'5': 'FIVE',
'6': 'SIX',
'7': 'SEVEN',
'8': 'EIGHT',
'9': 'NINE'
}
return conversion_dict[character] if character.isnumeric() else 'Character not numeric'
This should work if the user inputs the number as a string or integer data type. If you can control the data type input you would just delete the second line, and make sure the input character data type was in a string format.
For example, to use:
print(int_to_word(6))
print(int_to_word('7'))
output:
SIX
SEVEN
enter image description here
in the image please see the option c . I need a program in python.
I was trying to print number in word but I didn’t get successful. I want a answer in python.
def int_to_word(character):
character = str(character) if type(character)!=str else None
conversion_dict = {
'1': 'ONE',
'2': 'TWO',
'3': 'THREE',
'4': 'FOUR',
'5': 'FIVE',
'6': 'SIX',
'7': 'SEVEN',
'8': 'EIGHT',
'9': 'NINE'
}
return conversion_dict[character] if character.isnumeric() else 'Character not numeric'
This should work if the user inputs the number as a string or integer data type. If you can control the data type input you would just delete the second line, and make sure the input character data type was in a string format.
For example, to use:
print(int_to_word(6))
print(int_to_word('7'))
output:
SIX
SEVEN