Advertisement
Guest User

AT

a guest
Dec 9th, 2019
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. import csv
  2. lista = []
  3.  
  4.  
  5. with open('carros.csv', newline='') as csvfile:
  6. linha = csv.reader(csvfile, delimiter=',')
  7. for item in linha:
  8. lista.append(item)
  9.  
  10. for i in range(len(lista)):
  11. for j in range(len(lista[i])):
  12. if lista[i][j].isnumeric():
  13. lista[i][j] = float(lista[i][j])
  14.  
  15.  
  16. somatotal = 0
  17. menormedia = 0
  18. index = -1
  19.  
  20. for i in range(len(lista)):
  21. for j in range(len(lista[i])):
  22. if j > 0:
  23. if j == 3:
  24. somatotal += 10000 / (lista[i][j] / 10) * 3.98
  25. continue
  26. somatotal += lista[i][j]
  27. if i == 0:
  28. menormedia = somatotal
  29. if menormedia > somatotal:
  30. menormedia = somatotal
  31. index = i
  32. print(f"A média do {lista[i][0]} é {somatotal:.2f}")
  33. somatotal = 0
  34.  
  35.  
  36. print(f"A melhor média é do {lista[index][0]} gastando um total de {menormedia:.2f}")
  37.  
  38.  
  39. #ARQUIVOS
  40.  
  41. Chevrolet Onix,36000,1400,118,1600
  42. Ford Fiesta,32000,1300,135,1800
  43. VW Fox,31000,1450,123,1800
  44. VW Polo,41000,1600,135,1500
  45. Hiunday HB20,40000,1200,116,1200
  46. Renault Sandero,30000,1300,128,1900
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement