Created
November 30, 2019 11:15
-
-
Save MM-coder/d0d6a312ec729f6bbcc3ce03416749fb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
amigos = {} | |
lines = open("picnic.txt").readlines() | |
for line in lines: | |
line = line.split() | |
amigo = line[0] | |
amigos[amigo] = {} | |
i = 1 | |
while i < len(line): | |
comida = line[i] | |
quantidade = int(line[i+1]) | |
amigos[amigo][comida] = quantidade | |
i += 2 | |
def total_trazido(convidados: dict, item): | |
# INSERE O TEU CODIGO AQUI | |
quant = 0 | |
for i in convidados: | |
comida_por_cada = convidados[i] | |
for x in comida_por_cada: | |
if x == item: | |
quant += comida_por_cada[x] | |
return quant | |
# INSERE O TEU CODIGO ACIMA DESTA LINHA | |
print("O numero total de coisas no picnic foi de:") | |
print(" - Peras : "+str(total_trazido(amigos,'peras'))) | |
print(" - Laranjas : "+str(total_trazido(amigos,'laranjas'))) | |
print(" - Croissants : "+str(total_trazido(amigos,'croissants'))) | |
print(" - Cenouras : "+str(total_trazido(amigos,'cenouras'))) | |
print(" - Bolos : "+str(total_trazido(amigos,'bolos'))) | |
print(" - Sandes : "+str(total_trazido(amigos,'sandes'))) | |
print(" - Tartes : "+str(total_trazido(amigos,'tartes'))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sara laranjas 4 croissants 3 sumos 2 | |
Ines laranjas 1 peras 5 sandes 3 | |
Pedro sandes 5 cenouras 2 bolos 4 croissants 1 | |
Manuel tartes 5 laranjas 7 sumos 4 | |
Carlos bolos 3 sandes 6 peras 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment