-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
M_no-numerals.py
32 lines (21 loc) · 990 Bytes
/
M_no-numerals.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
"""
No Numerals
You write a phrase and include a lot of number characters (0-9), but you decide that for numbers 10 and under you would rather write the word out instead. Can you go in and edit your phrase to write out the name of each number instead of using the numeral?
Task:
Take a phrase and replace any instances of an integer from 0-10 and replace it with the English word that corresponds to that integer.
Input Format:
A string of the phrase in its original form (lowercase).
Output Format:
A string of the updated phrase that has changed the numerals to words.
Sample Input:
i need 2 pumpkins and 3 apples
Sample Output:
i need two pumpkins and three apples
"""
nums = ['zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten']
kinds = dict(enumerate(nums))
text = input()
for word in text.split():
if word.isdigit() and int(word) in kinds.keys():
text = text.replace(word, kinds.get(int(word)))
print(text)