15def answer(query):
16 parts = query.query.split()
17
18 if len(parts) < 2:
19 return []
20
21 try:
22 args = list(map(float, parts[1:]))
23 except:
24 return []
25
26 func = parts[0]
27 _answer = None
28
29 if func == 'min':
30 _answer = min(args)
31 elif func == 'max':
32 _answer = max(args)
33 elif func == 'avg':
34 _answer = sum(args) / len(args)
35 elif func == 'sum':
36 _answer = sum(args)
37 elif func == 'prod':
38 _answer = reduce(mul, args, 1)
39
40 if _answer is None:
41 return []
42
43 return [{'answer': str(_answer)}]
44
45
46
47