blob: 64b8f29664792750aa612998c10b664d3df33129 (
plain) (
blame)
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
|
#!/usr/bin/env python
# -*- coding: utf-8 -*-
def read_data():
data = []
while True:
text = raw_input()
if text == '':
break
try:
sp = text.split()
(value, cost) = map(float, sp)
data.append((cost / value, value, cost, text))
except ValueError:
pass
return data
def main():
print 'Enter data table (last line should be empty): value cost'
print
data = sorted(read_data())
if len(data):
print '%10s | %10s | %10s' % ("Ratio", "Value", "Cost")
for ratio, _, _, orig_value in data:
print '%10.2f | %10s | %10s' % tuple([ratio, ] + orig_value.split())
print
print 'Best choose is %s' % data[0][-1]
if __name__ == '__main__':
try:
main()
except KeyboardInterrupt:
pass
|