summaryrefslogtreecommitdiff
path: root/python/borsa.py
blob: 625ed1cd21605fa58adfc321ae973c2bdd1e78ca (plain)
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
38
39
class ValoreNegativo:
    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:
        print(ValoreNegativo)


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))