Filters are used with the |filter syntax:
{% elif student.department|upper != "MATHS DEPARTMENT" %}
Maths department
{% endif %}
or you can use the str.upper() method:
{% elif student.department.upper() != "MATHS DEPARTMENT" %}
Maths department
{% endif %}
Jinja syntax is Python-like, not actual Python.