From 77ae8ac9756a3e22a52612d6827a2f6b86b80e85 Mon Sep 17 00:00:00 2001 From: Santo Cariotti Date: Fri, 28 Apr 2017 18:32:58 +0200 Subject: Added borsa in python (only numbers >= 0) --- python/borsa.py | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 python/borsa.py 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 -- cgit v1.2.3-18-g5258