Untitled
unknown
python
9 months ago
1.4 kB
6
Indexable
def ReportPaese(T):
totali = []
# Per ogni riga (escludendo l'intestazione)
for i in range(1, len(T)):
for j in range(len(T[i])):
if i == 1: # se è la prima riga di dati
totali.append(T[i][j])
else:
totali[j] += T[i][j]
# Stampa risultati
for j in range(len(totali)):
print(T[0][j] + ":", totali[j])
def PaesiSottoSoglia(T, s):
# Per ogni paese (colonna)
for j in range(len(T[0])):
paese = T[0][j]
sotto_soglia = []
# Per ogni trimestre (riga, escludendo l'intestazione)
for i in range(1, len(T)):
if T[i][j] < s:
sotto_soglia.append(i)
if sotto_soglia:
print(paese, "è sotto soglia nel trimestre", end=" ")
for t in range(len(sotto_soglia)):
print(str(sotto_soglia[t]), end="")
if t < len(sotto_soglia)-1:
print(",", end=" ")
print()
# Test
T = [
["Italia", "Francia", "UK", "USA", "Grecia", "Svezia"],
[160, 200, 160, 300, 160, 250],
[260, 300, 260, 170, 260, 239],
[240, 256, 240, 220, 240, 277],
[180, 200, 180, 200, 40, 260]
]
print("Report totali per paese:")
ReportPaese(T)
print("\nPaesi sotto soglia (s=170):")
PaesiSottoSoglia(T, 170)Editor is loading...
Leave a Comment