diff options
| author | Anton Bobov <abobov@gmail.com> | 2018-01-17 19:54:16 +0500 |
|---|---|---|
| committer | Anton Bobov <abobov@gmail.com> | 2018-01-17 20:43:49 +0500 |
| commit | 941a793cbcf906725eec549a60eef3b3b3e80980 (patch) | |
| tree | a5e3fc6d8bf668bcc13d37a62053c3df901a05b5 | |
| parent | 2ade3efb7ca250f25e81dbe16efb7d8e84d3b036 (diff) | |
Worth it script.
| -rwxr-xr-x | worth-it | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/worth-it b/worth-it new file mode 100755 index 0000000..64b8f29 --- /dev/null +++ b/worth-it @@ -0,0 +1,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 |
