My index.html

{% extends "layout.html" %}

{% block title %}
{% endblock %}

{% block main %}
<!-- Seen from HTML of finance.cs50.net-->
<!-- making an int for storing the value of share prices at current value-->
{% set sum  = 0|int %}
<table class="table table-striped">

            <!-- for loop iterating over the stocks-->
            {% for stock in stocks %}
                <!-- obtaining value of stock from lookup function -->
                {% set i = stock['symbol']|lookup %}

                    <td>{{ i['symbol'] }}</td>
                    <td>{{ i['name'] }}</td>
                    <td>{{ stock['shares'] }}</td>
                    <td>{{ i['price'] }}</td>
                    <td>{{ i['price']*stock['shares'] }}</td>
                    <!-- making a variable and typecasting it to int-->
                    {% set j =  i['price']*stock['shares']|int%}
                    <!-- storing it in sum-->
                    {% set sum = sum + j %}


                <td colspan="4">CASH</td>
                <!--cash amount-->

                <td colspan="4"></td>
                <!-- add sum and cash-->
                <td>{{sum + cash_amt[0]['cash']}}</td>

{% endblock %}

Please help Image of result

How to solve the total problem :(


I tried the same. Then I found this one: http://jinja.pocoo.org/docs/2.9/templates/#assignments (basically: won't work)

I chose to calculate the total value in Python instead, and pass it in another variable.

  • Thanks for the quick reply :)
    – Crazy8
    Sep 23 '17 at 2:02

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .