B
B
Busyaska2021-11-27 18:40:21
Python
Busyaska, 2021-11-27 18:40:21

How to make the numbers from the dictionary sum up after iteration and parsing?

After iteration and parsing, it does not sum up the numbers, but either displays only the last one, or outputs each from a new line, or after "while True" infinitely sums and gives the error "TypeError: unsupported operand type(s) for +=: 'float' and ' NoneType'"

def searcher(url):
    rs = requests.get(url)
    m = re.search(r'var line1=(.+);', rs.text)
    data_str = m.group(1)
    data = json.loads(data_str)
    cost =data[-1]
    x = cost[1]
    return float(x)
def total_cost():
    average_costs = 0
    for average_cost in CSGO_Stickers_PGL_Major_Stockholm_2021.keys():
        average_costs += CSGO_Stickers_PGL_Major_Stockholm_2021[average_cost]
    for a,i in CSGO_Stickers_PGL_Major_Stockholm_2021_Current_Cost.items():
        cumma = 0
        cumma += searcher(i)
    print('Всего инвестировал в PGL Major Stockholm 2021', '%.2f' % average_costs+'$ с разницей', cumma)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vindicar, 2021-11-27
@Busyaska

cumma = 0
cumma += searcher(i)
What cucumber are you resetting the sum to 0 on each iteration of the loop? Of course 0 + x = x.
Carry out cumma = 0 per cycle, investor.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question