-
Notifications
You must be signed in to change notification settings - Fork 1
/
chatbot_warmup_task.py
72 lines (50 loc) · 1.53 KB
/
chatbot_warmup_task.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#Chatbot that translates arabic numbers to roman number
from collections import OrderedDict
def int_to_roman(arabic_num):
romanDict = OrderedDict()
romanDict[1000] = "M"
romanDict[900] = "CM"
romanDict[500] = "D"
romanDict[400] = "CD"
romanDict[100] = "C"
romanDict[90] = "XC"
romanDict[50] = "L"
romanDict[40] = "XL"
romanDict[10] = "X"
romanDict[9] = "IX"
romanDict[5] = "V"
romanDict[4] = "IV"
romanDict[1] = "I"
#iterate over all numbers in the list
result = []
for num in arabic_num:
roman_str = ""
if num <= 0:
return "Invalid number"
while (num !=0):
for base in romanDict.keys():
if base <= num:
quot = num / base
num = num % base
roman_str += romanDict[base]*quot
result.append(roman_str)
return result
def extract_numbers(query): #extracts numbers from the query
numbers = [int(q) for q in query.split() if q.isdigit()]
return numbers
def welcome():
print "Hi! This is a simple chatbot which translates arabic numbers to roman numbers."
if __name__ == "__main__":
welcome()
while(1):
query = raw_input("Enter your query (press e to exit): ")
if query == 'e' or query == 'E':
break
arabic_num = extract_numbers(query)
if len(arabic_num) == 0:
print "Invalid query"
continue
roman_num = int_to_roman(arabic_num)
for num in roman_num:
print num ,
print