-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path3_lerjsonxml.py
41 lines (31 loc) · 1.02 KB
/
3_lerjsonxml.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import json
def readJSON():
with open("./dados.json") as jsondir:
res = json.load(jsondir)
return res
def main():
data = readJSON()
total, mediaMensal, diasFaturados = 0, 0, 0
minVal, maxVal = float("inf"), 0
diasMedia = 0
for el in data:
val = el["valor"]
if val > 0:
diasFaturados += 1
total += val
if val < minVal:
minVal = val
if maxVal < val:
maxVal = val
mediaMensal = total/diasFaturados
for el in data:
val = el["valor"]
if val >= mediaMensal:
diasMedia += 1
print("Faturamento total:", format(total, ".2f"))
print("Média mensal:", format(mediaMensal, ".2f"))
print("Dia de menor faturamento:", format(minVal, ".2f"))
print("Dia de maior faturamento:", format(maxVal, ".2f"))
print("Dias com faturamento acima da média:", diasMedia)
return True
main()