summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSanto Cariotti <sancn@live.com>2017-04-28 18:32:58 +0200
committerSanto Cariotti <sancn@live.com>2017-04-28 18:32:58 +0200
commit77ae8ac9756a3e22a52612d6827a2f6b86b80e85 (patch)
tree6a99a328a69d42e177c3045114985dfb79bb2d2a
parentcb4611b43d40bb2a89646f3d797f4a05ba51683d (diff)
Added borsa in python (only numbers >= 0)
-rw-r--r--python/borsa.py39
1 files changed, 39 insertions, 0 deletions
diff --git a/python/borsa.py b/python/borsa.py
new file mode 100644
index 0000000..f62d12c
--- /dev/null
+++ b/python/borsa.py
@@ -0,0 +1,39 @@
+class ValoreNegativo(ValueError):
+ def __str__(self):
+ return 'Il valore non e\' maggiore di 0'
+
+a = []
+i = 0
+
+while i < 14:
+ try:
+ num = input()
+ if num < 0:
+ raise ValoreNegativo
+
+ a.append(num)
+ i += 1
+ except ValoreNegativo, e:
+ print(e)
+
+
+diff = i = 0
+tot = len(a)
+
+for i in range(tot):
+ minore = a[i]
+
+ for j in range(i, tot-1):
+ if a[j] == minore:
+ continue
+ elif a[j] > minore:
+ diffp = a[j] - minore
+
+ if diffp > diff and diffp > 0:
+ x = i
+ y = j
+ diff = diffp
+
+
+print('Ti conviene comprare a {} giorno {} e vendere a {} giorno {}'.format(a[x], x + 1, a[y], y + 1))
+print('Guadagneresti ' + str(diff)) \ No newline at end of file