-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgfg test.py
56 lines (45 loc) · 1.36 KB
/
gfg test.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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# ---------------- MSB's Coding Template ---------------- #
"""
"ɴᴏ ᴄᴏᴅᴇ ɪꜱ ᴘᴇʀꜰᴇᴄᴛ"
"""
# ---I/O from file---#
import sys
try:
sys.stdin = open("input.txt", "r", encoding="UTF-8")
sys.stdout = open("output.txt", "w", encoding="UTF-8")
sys.stderr = open("output.txt", "w", encoding="UTF-8")
except FileNotFoundError as __:
pass
# ---------------------- Code Starts Here ----------------------#
def convert_words_to_digits(inp):
# Mapping words to corresponding digits
word_to_digit_map = {
"zero": "0",
"one": "1",
"two": "2",
"three": "3",
"four": "4",
"five": "5",
"six": "6",
"seven": "7",
"eight": "8",
"nine": "9",
}
word_list = inp.split()
phone_number = ""
index = 0
while index < len(word_list):
if word_list[index] == "double":
digit = word_to_digit_map[word_list[index + 1]]
phone_number += digit * 2
index += 2
elif word_list[index] == "triple":
digit = word_to_digit_map[word_list[index + 1]]
phone_number += digit * 3
index += 2
else:
phone_number += word_to_digit_map[word_list[index]]
index += 1
return phone_number
if __name__ == "__main__":
print(convert_words_to_digits(str(input())))