0

I'm trying to compare actual_time and taken_seconds, but less than operators (<) show in red color, and it actually not compare the numbers.As per image, 6<12, it should say Time taken is higher than actual time of gesturing

    <h5>Actual time: {{ actual_time }} seconds</h5>
    <h5>Taken time: {{ taken_time }} seconds ({{ taken_seconds }} seconds)</h5>
    <h5>Point: {{ point }}</h5>

    {% if actual_time < taken_seconds %}
    <div class="alert alert-warning" role="alert">
        Time taken is higher than actual time which may lead to fatigue.
    </div>
    {% elif actual_time > taken_seconds %}
    <div class="alert alert-success" role="alert">
        Time taken is lower than actual time of gesturing.
    </div>
    {% endif %}

.

Toufiqur Rahman
  • 202
  • 3
  • 17

1 Answers1

1

It looks like your actual_time and taken_seconds are not of type int. They are likely strings which results in this comparison. Try converting them to int first to then compare.

As strings I can reproduce your problem:

In [1]: actual_time = '6'
In [2]: taken_seconds = '12'
In [3]: actual_time < taken_seconds
Out[3]: False
In [4]: actual_time  > taken_seconds
Out[4]: True

See @Abdul Aziz Barkat comment to coerce the strings and this Stack Overflow post here. I would recommend ensuring they are int first before passing them to the template though.

Dean Elliott
  • 1,245
  • 1
  • 8
  • 12