How to assign and use variables in Flow for order costs?

Hello,

I am having trouble creating and then using variables in Shopify Flow. Specifically I want to sum the unit costs for the current order and add them to the order note.

{% assign unit_cost_sum = 0 %}
{% for fulfillmentLineItems_item in fulfillment.fulfillmentLineItems %}
{% assign unit_cost_sum = fulfillmentLineItems_item.lineItem.variant.inventoryItem.unitCost.amount | times: fulfillmentLineItems_item.lineItem.quantity | plus: unit_cost_sum %}
{% endfor %}
{{ unit_cost_sum }}

I get an error if I include the last line “{{ unit_cost_sum }}”. Here is a screenshot:

It allows me to apply the changes if I exclude that line. What am I missing?