blob: 35fd276c0174638a6834cb2305f27503d1acc4d3 (
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 python3
# -*- coding: utf-8 -*-
def read_data():
data = []
while True:
text = input()
if text == '':
break
try:
sp = text.split()
(value, cost) = list(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
|