diff options
author | Santo Cariotti <sancn@live.com> | 2017-05-09 17:03:01 +0200 |
---|---|---|
committer | Santo Cariotti <sancn@live.com> | 2017-05-09 17:03:01 +0200 |
commit | 1c30cab072b066b60961d055a446a67124924034 (patch) | |
tree | a6aa5ba8f0476bdbc9efa98e9f441b9bbf7075fe | |
parent | b847b96ca6eda633f48a0a80a17d1c1632c87f29 (diff) |
Added computer science test (8/5/17) in python
-rw-r--r-- | python/compito.py | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/python/compito.py b/python/compito.py new file mode 100644 index 0000000..17b5b67 --- /dev/null +++ b/python/compito.py @@ -0,0 +1,74 @@ +class puntiVedita: + def __init__(self): + citta = '' + entrate = uscite = 0 + +pV = [puntiVedita() for i in range(5)] + +def carica(): + pV[0].citta = "Catania"; + pV[0].entrate = 380; + pV[0].uscite = 245; + pV[1].citta = "Ragusa"; + pV[1].entrate = 231; + pV[1].uscite = 175; + pV[2].citta = "Siracusa"; + pV[2].entrate = 214; + pV[2].uscite = 227; + pV[3].citta = "Messina"; + pV[3].entrate = 294; + pV[3].uscite = 189; + pV[4].citta = "Enna"; + pV[4].entrate = 145; + pV[4].uscite = 175; + + +def ord(): + s = True + t = puntiVedita() + last = 4 + + while s: + s = False + + for i in range(last): + if pV[i].entrate > pV[i+1].entrate: + t.citta = pV[i].citta; + t.entrate = pV[i].entrate; + t.uscite = pV[i].uscite; + + pV[i].citta = pV[i+1].citta; + pV[i].entrate = pV[i+1].entrate; + pV[i].uscite = pV[i+1].uscite; + + + pV[i+1].citta = t.citta; + pV[i+1].entrate = t.entrate; + pV[i+1].uscite = t.uscite; + + s = True; + + last -= 1 + + +def util(p): + if p.entrate < p.uscite: + r = False + else: + r = True + + return r + + +for i in pV: + carica() + + if not util(i): + print("Attenzione -> {}".format(i.citta)) + +ord() + +for i in pV: + print(i.entrate) + + |