feat: Initial commit
This commit is contained in:
44
simulazioni/astrologia/main.py
Normal file
44
simulazioni/astrologia/main.py
Normal file
@@ -0,0 +1,44 @@
|
||||
import csv
|
||||
|
||||
segni = {}
|
||||
somma = 0
|
||||
|
||||
with open("zodiaco.csv") as csv_file:
|
||||
csv_reader = csv.reader(csv_file)
|
||||
|
||||
for row in csv_reader:
|
||||
data_start = row[1]
|
||||
data_start = data_start.split("/")
|
||||
data_start = int(data_start[1] + data_start[0])
|
||||
|
||||
data_end = row[2]
|
||||
data_end = data_end.split("/")
|
||||
data_end = int(data_end[1] + data_end[0])
|
||||
|
||||
nome = row[0]
|
||||
|
||||
segni[nome] = {"start": data_start, "end": data_end, "goals": 0}
|
||||
|
||||
|
||||
with open("sportivi.csv") as csv_file:
|
||||
csv_reader = csv.reader(csv_file)
|
||||
|
||||
for row in csv_reader:
|
||||
data = row[1]
|
||||
data = data.split("/")
|
||||
data = int(data[1] + data[0])
|
||||
|
||||
goals = row[0]
|
||||
|
||||
for segno in segni:
|
||||
if segni[segno]["start"] < data < segni[segno]["end"]:
|
||||
segni[segno]["goals"] += goals
|
||||
somma += goals
|
||||
break
|
||||
|
||||
|
||||
for segno in segni:
|
||||
dati = segni[segno]
|
||||
barra = "*"*int((dati[goals] / somma) * 50)
|
||||
|
||||
print(f"${segno} (${dati['goals']}): ${barra}")
|
||||
4
simulazioni/discografia/acdc.txt
Normal file
4
simulazioni/discografia/acdc.txt
Normal file
@@ -0,0 +1,4 @@
|
||||
1978;Kicked In The Teeth
|
||||
1985;Playing with Girls
|
||||
1985;Shake Your Foundations
|
||||
1990;Thunderstruck
|
||||
3
simulazioni/discografia/artisti.txt
Normal file
3
simulazioni/discografia/artisti.txt
Normal file
@@ -0,0 +1,3 @@
|
||||
01023;queen.txt
|
||||
02346;kiss.txt
|
||||
16750;acdc.txt
|
||||
3
simulazioni/discografia/kiss.txt
Normal file
3
simulazioni/discografia/kiss.txt
Normal file
@@ -0,0 +1,3 @@
|
||||
1980;Two Sides of the Coin
|
||||
1985;King Of The Mountain
|
||||
1979;I Was Made for Lovin' You
|
||||
31
simulazioni/discografia/main.py
Normal file
31
simulazioni/discografia/main.py
Normal file
@@ -0,0 +1,31 @@
|
||||
songs = dict()
|
||||
|
||||
artists = open("artisti.txt", "r")
|
||||
|
||||
for artist in artists:
|
||||
artist = artist.split(";")
|
||||
artCode = artist[0].strip()
|
||||
|
||||
songsFile = open(artist[1].strip(), "r")
|
||||
|
||||
for song in songsFile:
|
||||
song = song.split(";", 1)
|
||||
year = song[0]
|
||||
title = song[1].strip()
|
||||
|
||||
if year not in songs:
|
||||
songs[year] = []
|
||||
|
||||
songs[year].append({"artist": artCode, "title": title})
|
||||
|
||||
songsFile.close()
|
||||
|
||||
artists.close()
|
||||
|
||||
years = sorted(list(songs.keys()))
|
||||
|
||||
for year in years:
|
||||
print(year + ":")
|
||||
|
||||
for s in songs[year]:
|
||||
print(s["title"] + "\t" + s["artist"])
|
||||
3
simulazioni/discografia/queen.txt
Normal file
3
simulazioni/discografia/queen.txt
Normal file
@@ -0,0 +1,3 @@
|
||||
1980;Crazy Little Thing Called Love
|
||||
1985;It’s a kind of magic
|
||||
1978;Under pressure
|
||||
9
simulazioni/hacking/acquisti.txt
Normal file
9
simulazioni/hacking/acquisti.txt
Normal file
@@ -0,0 +1,9 @@
|
||||
P234HF22223 r1112
|
||||
P111TG11115 r1015
|
||||
P111TG11115 r1216
|
||||
P234HF22222 r1011
|
||||
P331LS00110 r1014
|
||||
P331LS00120 r1318
|
||||
P331LS00130 r1019
|
||||
P234HF22225 r1114
|
||||
P234HF22223 r1114
|
||||
71
simulazioni/hacking/hacking.py
Normal file
71
simulazioni/hacking/hacking.py
Normal file
@@ -0,0 +1,71 @@
|
||||
from sys import exit
|
||||
|
||||
def carica_prodotti(filename: str):
|
||||
try:
|
||||
fio = open(filename, "r")
|
||||
|
||||
prodotti = dict()
|
||||
|
||||
for line in fio:
|
||||
line = line.strip().split()
|
||||
prodotti[line[0]] = line[1]
|
||||
|
||||
fio.close()
|
||||
return prodotti
|
||||
except FileNotFoundError:
|
||||
exit("Errore! Il file", filename, "non è stato trovato!")
|
||||
|
||||
|
||||
def carica_acquisti(filename: str, prodotti: dict):
|
||||
try:
|
||||
fio = open(filename, "r")
|
||||
|
||||
prodotti_sospetti = dict()
|
||||
|
||||
for line in fio:
|
||||
line = line.strip().split()
|
||||
prodotto = line[0]
|
||||
rivenditore = line[1]
|
||||
|
||||
if prodotto not in prodotti:
|
||||
print("Attenzione! il prodotto", prodotto, "non esiste")
|
||||
continue
|
||||
|
||||
if prodotto not in prodotti_sospetti:
|
||||
prodotti_sospetti[prodotto] = []
|
||||
|
||||
prodotti_sospetti[prodotto].append(rivenditore)
|
||||
|
||||
fio.close()
|
||||
return prodotti_sospetti
|
||||
except FileNotFoundError:
|
||||
exit("Errore! Il file", filename, "non è stato trovato!")
|
||||
|
||||
|
||||
def controlla_acquisti(prodotti: dict, acquisti: dict):
|
||||
prodotti_sospetti = dict()
|
||||
for prodotto in acquisti:
|
||||
if len(acquisti[prodotto]) > 1 or (len(acquisti[prodotto]) == 1 and acquisti[prodotto][0] != prodotti[prodotto]):
|
||||
prodotti_sospetti[prodotto] = acquisti[prodotto]
|
||||
|
||||
return prodotti_sospetti
|
||||
|
||||
|
||||
def stampa_prodotti_sospetti(prodotti: dict, prodotti_sospetti: dict):
|
||||
print("Elenco transazioni sospette")
|
||||
for prodotto in prodotti_sospetti:
|
||||
print("Codice prodotto:", prodotto)
|
||||
print("Rivenditore ufficiale:", prodotti[prodotto])
|
||||
print("Lista rivenditori:", " ".join(prodotti_sospetti[prodotto]))
|
||||
print()
|
||||
|
||||
|
||||
def main():
|
||||
prodotti = carica_prodotti("prodotti.txt")
|
||||
acquisti = carica_acquisti("acquisti.txt", prodotti)
|
||||
sospetti = controlla_acquisti(prodotti, acquisti)
|
||||
stampa_prodotti_sospetti(prodotti, sospetti)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
8
simulazioni/hacking/prodotti.txt
Normal file
8
simulazioni/hacking/prodotti.txt
Normal file
@@ -0,0 +1,8 @@
|
||||
P234HF22222 r1011
|
||||
P234HF22223 r1112
|
||||
P234HF22225 r1114
|
||||
P111TG11115 r1015
|
||||
P111TG11115 r1216
|
||||
P331LS00110 r1017
|
||||
P331LS00120 r1318
|
||||
P331LS00130 r1019
|
||||
3
simulazioni/murphy/argomenti.txt
Normal file
3
simulazioni/murphy/argomenti.txt
Normal file
@@ -0,0 +1,3 @@
|
||||
male
|
||||
fretta
|
||||
lavoro
|
||||
23
simulazioni/murphy/leggi_di_Murphy.txt
Normal file
23
simulazioni/murphy/leggi_di_Murphy.txt
Normal file
@@ -0,0 +1,23 @@
|
||||
Principio degli elementi persi
|
||||
Il raggio di caduta dal banco di lavoro di piccoli elementi varia inversamente alle loro dimensioni - e direttamente alla loro importanza per il completamento del lavoro intrapreso.
|
||||
|
||||
Legge di Perussel
|
||||
Non c'è lavoro tanto semplice che non possa essere fatto male.
|
||||
|
||||
Regola di Ray sulla precisione
|
||||
Misura con un micrometro.
|
||||
Segna con un gessetto.
|
||||
Taglia con un'ascia.
|
||||
|
||||
Legge dei semafori
|
||||
Se è verde non hai fretta.
|
||||
|
||||
Legge di Pudder
|
||||
Chi ben comincia, finisce male. Chi comincia male, finisce peggio.
|
||||
|
||||
Seconda Legge di Horowitz
|
||||
In qualunque momento tu accenda la radio, sentirai le ultime note della tua canzone preferita.
|
||||
|
||||
Legge di Vile sul valore
|
||||
Più un oggetto costa, più lontano bisognerà spedirlo per farlo riparare.
|
||||
|
||||
67
simulazioni/murphy/murphy.py
Normal file
67
simulazioni/murphy/murphy.py
Normal file
@@ -0,0 +1,67 @@
|
||||
from string import punctuation
|
||||
|
||||
|
||||
def carica_leggi(filename: str):
|
||||
try:
|
||||
fio = open(filename, "r")
|
||||
|
||||
leggi = {}
|
||||
|
||||
titolo = fio.readline()
|
||||
|
||||
while titolo != "":
|
||||
linea = fio.readline()
|
||||
legge = ""
|
||||
|
||||
while linea != "\n" and linea != "":
|
||||
legge += linea.strip()
|
||||
linea = fio.readline()
|
||||
|
||||
leggi[titolo.strip()] = legge
|
||||
|
||||
titolo = fio.readline()
|
||||
|
||||
fio.close()
|
||||
except FileNotFoundError:
|
||||
exit(f"Errore: Il file {filename} non è stato trovato!")
|
||||
except IOError:
|
||||
exit("Errore: Si è verificato un problema durante la lettura del file!")
|
||||
|
||||
return leggi
|
||||
|
||||
|
||||
def carica_argomenti(filename: str):
|
||||
try:
|
||||
fio = open(filename, "r")
|
||||
argomenti = [arg.strip() for arg in fio]
|
||||
fio.close()
|
||||
except FileNotFoundError:
|
||||
exit(f"Errore: Il file {filename} non è stato trovato!")
|
||||
return argomenti
|
||||
|
||||
|
||||
def rimuovi_punteggiatura(stringa: str):
|
||||
for p in punctuation:
|
||||
stringa = stringa.replace(p, " ")
|
||||
|
||||
return stringa
|
||||
|
||||
|
||||
def main():
|
||||
leggi = carica_leggi("leggi_di_Murphy.txt")
|
||||
argomenti = carica_argomenti("argomenti.txt")
|
||||
|
||||
for legge in leggi:
|
||||
testo_legge = leggi[legge]
|
||||
parole = rimuovi_punteggiatura(testo_legge.lower()).split()
|
||||
|
||||
for argomento in argomenti:
|
||||
if argomento in parole:
|
||||
if len(testo_legge) > 50:
|
||||
testo_legge = testo_legge[:50] + "..."
|
||||
print(legge, "-", testo_legge)
|
||||
break
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
55
simulazioni/piramidi/main.py
Normal file
55
simulazioni/piramidi/main.py
Normal file
@@ -0,0 +1,55 @@
|
||||
from sys import exit
|
||||
|
||||
def carica_piramide(filename: str):
|
||||
try:
|
||||
fio = open(filename, "r")
|
||||
except FileNotFoundError:
|
||||
exit(f"Attenzione! {filename} non trovato")
|
||||
|
||||
mappa = []
|
||||
|
||||
for i in fio:
|
||||
righa = [int(c) for c in i.strip().split()]
|
||||
mappa.append(righa)
|
||||
|
||||
fio.close()
|
||||
|
||||
return mappa
|
||||
|
||||
|
||||
def lista_adiacenti(mappa: list, x: int, y: int):
|
||||
items = []
|
||||
|
||||
for a in range(max(0, x - 1), min(x + 2, len(mappa))):
|
||||
for b in range(max(0, y - 1), min(y + 2, len(mappa[x]))):
|
||||
if a == x and b == y:
|
||||
continue
|
||||
|
||||
items.append(mappa[a][b])
|
||||
|
||||
return items
|
||||
|
||||
|
||||
def cerca_piramidi(mappa: list):
|
||||
somma_altezze = 0
|
||||
numero_piramidi = 0
|
||||
|
||||
for x in range(len(mappa)):
|
||||
for y in range(len(mappa[x])):
|
||||
altezza_massima = max(lista_adiacenti(mappa, x, y))
|
||||
|
||||
if mappa[x][y] > altezza_massima:
|
||||
print(mappa[x][y], x, y)
|
||||
somma_altezze += mappa[x][y]
|
||||
numero_piramidi += 1
|
||||
|
||||
|
||||
return somma_altezze / numero_piramidi
|
||||
|
||||
def main():
|
||||
mappa = carica_piramide("mappa.txt")
|
||||
media = cerca_piramidi(mappa)
|
||||
print(f"Altezza media: {media} m")
|
||||
|
||||
|
||||
main()
|
||||
10
simulazioni/piramidi/mappa.txt
Normal file
10
simulazioni/piramidi/mappa.txt
Normal file
@@ -0,0 +1,10 @@
|
||||
3 4 4 4 3 2 1 0 0 0
|
||||
3 4 5 4 3 2 1 1 1 1
|
||||
3 4 4 4 3 2 2 2 2 1
|
||||
3 3 3 3 3 3 3 3 2 1
|
||||
2 2 2 2 2 3 4 3 2 1
|
||||
1 1 1 1 2 3 3 3 2 1
|
||||
0 0 0 1 2 2 2 2 2 1
|
||||
0 0 0 1 1 1 1 1 1 1
|
||||
0 1 0 0 0 0 0 0 0 0
|
||||
0 0 0 0 0 0 1 0 0 0
|
||||
39
simulazioni/polizia/main.py
Normal file
39
simulazioni/polizia/main.py
Normal file
@@ -0,0 +1,39 @@
|
||||
file = open("presenze.txt", "r")
|
||||
|
||||
presenze = dict()
|
||||
|
||||
for i in file:
|
||||
i = i.split("f")
|
||||
presenza = dict()
|
||||
presenza["number"] = i[1]
|
||||
presenza["start"] = int(i[2])
|
||||
presenza["end"] = int(i[3])
|
||||
presenze[i[0]] = presenza
|
||||
|
||||
file.close()
|
||||
file = open("sospetti.txt", "r")
|
||||
|
||||
for sospetto in file:
|
||||
sospetto = sospetto.strip()
|
||||
if sospetto not in presenze:
|
||||
continue
|
||||
|
||||
inizio = presenze[sospetto]["start"]
|
||||
fine = presenze[sospetto]["end"]
|
||||
|
||||
notFound = True
|
||||
|
||||
print("** Contatti del cliente :", sospetto, "**")
|
||||
|
||||
for nome in presenze:
|
||||
if nome == sospetto:
|
||||
continue
|
||||
|
||||
if min(fine, presenze[nome]["end"]) - max(inizio, presenze[nome]["start"]) > 0:
|
||||
notFound = False
|
||||
print("\tContatto con "+ nome + ", telefono "+presenze[nome]["number"])
|
||||
|
||||
if notFound:
|
||||
print("\tll cliente", sospetto, "non ha avuto contatti")
|
||||
|
||||
file.close()
|
||||
7
simulazioni/prodotti/input.txt
Normal file
7
simulazioni/prodotti/input.txt
Normal file
@@ -0,0 +1,7 @@
|
||||
SKU012345 Coltello 7.50 ITA 9.4 8.9 9.7 9.7 9.8
|
||||
SKU012346 Piatto 10.00 ITA 9.0 9.0 9.0 9.2 9.5
|
||||
SKU012347 Bicchiere 8.30 USA 8.4 8.7 8,5 8.6 9.0
|
||||
SKU012348 Piatto 7.30 RUS 8.4 8.7 9.5 9.6 9.0
|
||||
SKU012349 Bicchiere 5.10 GRB 8,2 8.9 8.9 8.6 9.3
|
||||
SKU012350 Forchetta 5,00 USA 8.2 8.9 8.9 8.6 9.3
|
||||
SKU012351 Coltello 7.20 GRB 8.0 8.0 8.0 8.0 8.0
|
||||
67
simulazioni/prodotti/prodotti.py
Normal file
67
simulazioni/prodotti/prodotti.py
Normal file
@@ -0,0 +1,67 @@
|
||||
import operator
|
||||
|
||||
|
||||
def calcola_punteggio(punteggi: list):
|
||||
punteggi_ordinati = sorted(punteggi, reverse=True)
|
||||
return float(punteggi_ordinati[0]) + float(punteggi_ordinati[1]) + float(punteggi_ordinati[3])
|
||||
|
||||
|
||||
def leggi_file(filename: str):
|
||||
fio = open(filename, "r")
|
||||
|
||||
prodotti = []
|
||||
|
||||
for line in fio:
|
||||
line = line.strip().split(" ")
|
||||
codice = line[0]
|
||||
categoria = line[1]
|
||||
costo = line[2]
|
||||
nazione = line[3]
|
||||
punteggio_totale = calcola_punteggio(line[4::])
|
||||
|
||||
prodotti.append({"codice": codice, "categoria": categoria, "costo": costo, "nazione": nazione, "punteggio": punteggio_totale})
|
||||
|
||||
fio.close()
|
||||
return prodotti
|
||||
|
||||
|
||||
def prodotto_vincente(prodotti: list):
|
||||
stati = {} # stato: punteggio
|
||||
categorie = {} # categoria: [codice, valore]
|
||||
|
||||
prodotto_vincente = 0
|
||||
|
||||
for i in range(len(prodotti)):
|
||||
prodotto = prodotti[i]
|
||||
categoria = prodotto["categoria"]
|
||||
nazione = prodotto["nazione"]
|
||||
codice = prodotto["codice"]
|
||||
punteggio = prodotto["punteggio"]
|
||||
|
||||
if punteggio > prodotti[prodotto_vincente]["punteggio"]:
|
||||
prodotto_vincente = i
|
||||
|
||||
if categoria not in categorie or punteggio > categorie[categoria][1]:
|
||||
categorie[categoria] = [codice, punteggio]
|
||||
|
||||
if nazione not in stati:
|
||||
stati[nazione] = punteggio
|
||||
else:
|
||||
stati[nazione] += punteggio
|
||||
|
||||
stati = sorted(stati, key=operator.itemgetter(1))
|
||||
|
||||
print("Prodotto vincente", prodotti[prodotto_vincente]["codice"])
|
||||
print("I primi tre stati vincenti sono: ", stati[0], stati[1], stati[2])
|
||||
|
||||
for categoria in categorie:
|
||||
print("Il vincitore della categoria", categoria, "è il prodotto", categorie[categoria][0])
|
||||
|
||||
|
||||
def main():
|
||||
prodotti = leggi_file("input.txt")
|
||||
prodotto_vincente(prodotti)
|
||||
|
||||
main()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user