'How to use all the values of a list and use it in an equation?

I've posted my first question here which is also linked to this question: Link

How do I use all the values in a list containing values e.g. [10,20,30,40,50] and use it in an equation?

price = [10,20,30,40,50]
total_balance = (balanceA + balanceB) * price

I'm hoping it would use each element inside the list as the value for the variable price and would result in a list (total_balance) that contains the result computed for each element inside that price list using the equation. I've googled questions similar to mine but they only use one value inside the list.



Solution 1:[1]

Just loop through the list:

price = [10,20,30,40,50]
total_balance = []
for p in price: # Go through every value in the price list
    tmp_price = (balanceA + balanceB) * p # You calculate the price with the selected value here
    total_balance.append(tmp_price) # Here you add your calculated price to your list with all prices

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Pythonwolf