summaryrefslogtreecommitdiff
path: root/worth-it
diff options
context:
space:
mode:
authorAnton Bobov <abobov@gmail.com>2018-01-17 19:54:16 +0500
committerAnton Bobov <abobov@gmail.com>2018-01-17 20:43:49 +0500
commit941a793cbcf906725eec549a60eef3b3b3e80980 (patch)
treea5e3fc6d8bf668bcc13d37a62053c3df901a05b5 /worth-it
parent2ade3efb7ca250f25e81dbe16efb7d8e84d3b036 (diff)
Worth it script.
Diffstat (limited to 'worth-it')
-rwxr-xr-xworth-it37
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