So, I have a number which is total_ttc and products that have their original price and the tva (code attached below). What I am trying to do is find a combination of random products with random quantities who’s price adds up to the total_ttc which I have already defined.
This is my existing code, this does not provide the exact total_ttc but the closest to the total_ttc
import random
total_ttc = 362400
total_amount = 0
while total_amount < total_ttc:
random_product = random.choice(dict_products)
random_quantity = random.randint(1, 20)
product_name = random_product["nom d'article"]
product_price = random_product["prix unitaire ht"]
product_tva = random_product["taux tva"]
calculated_price = (product_price * random_quantity) + (product_price * product_tva)
if total_amount + calculated_price > total_ttc - 100:
break
total_amount += calculated_price
print(total_amount)