generate functionSat, 18 Mar 2023

The Ministry of the Interior wishes to analyze the prison population of the Italian regions. To this end, after having requested, for each region: the identification code, the number of inhabitants (population), the number of prisoners calculate, for each region, the percentage of inhabitants and the percentage of prisoners respectively on the national total of population and prisoners.

def percentage(v, tot): pc = (v / tot) * 100 return pc def region(idr, popr, prr, totpop, totpr): pc_popr = percentage(popr, totpop) pc_prr = percentage(prr, totpr) return idr, pc_popr, pc_prr def italy(idr, popr, prr, totpop, totpr): lista = [] for i in range(idr): a, b, c = region(i, popr[i], prr[i], totpop, totpr) lista.append(a, b, c) return lista region_id = [1, 2, 3, 4, 5] pop_region = [10, 20, 30, 40, 50] pr_region = [1, 2, 3, 4, 5] tot_pop = sum(pop_region) tot_pr = sum(pr_region) print (ital

Questions about programming?Chat with your personal AI assistant