Code issues in a template with a loop

Hello everyone. Following a tutorial from Smart Home Junkie, I made Templates to return the expected rainfall per day, using the openweathermap API. however the template explained does not work. This is apparently the part with

{% for daypart in range(0 ,7) %}

This part gives me a problem.

# essai "Météo de la journée selon Smart Home Junkie"
- trigger:
    - platform: homeassistant
      event: start
    - platform: time_pattern
      minutes: /20
  action:
    - service: weather.get_forecast
      data:
        type: hourly
      target:
        entity_id:
          - weather.openweathermap
      response_variable: my_forcast

  sensor:
    - name: "Météo of the day by Smart Home Junkie"
      unique_id: 14485d6d-fb53-4e72-aea6-85f613b015ee
      icon: mdi:weather-pouring
      unit_of_measurement: mm
      state: >
        {% set ns = namespace() %}
        {% set ns.totalprecipitation = 0 %}
        {% for daypart in range(0 ,7) %}
          {% set precipitation = my_forcast.forecast[daypart].precipitation %}
          {% set precipitation_probability = my_forcast.forecast[daypart].precipitation_probability / 100 %}
          {% if precipitation_probability > 0 %}
           {% set precipitation = precipitation * precipitation_ probability %}
          {% endif %}
          {% set ns.totalprecipitation = ns.totalprecipitation + precipitation %}
        {% endfor %}
        {{ ns.totalprecipitation |  float(0) | round(2) }}

Any idea what my code is missing???
I circumvented with the sum of [daypart] by replacing [daypart] with [0],…,[7]

Thank you for your suggestions.

  1. You’re missing {% set my_forcast = states.weather.owm_daily.attributes %}
  2. You have a bogus blank after the underscore in {% set precipitation = precipitation * precipitation_ probability %}
{% set ns = namespace() %}
{% set ns.totalprecipitation = 0 %}
{% set my_forcast = states.weather.owm_daily.attributes %}
{% for daypart in range(0 ,7) %}
  {% set precipitation = my_forcast.forecast[daypart].precipitation %}
  {% set precipitation_probability = my_forcast.forecast[daypart].precipitation_probability / 100 %}
  {% if precipitation_probability > 0 %}
   {% set precipitation = precipitation * precipitation_probability %}
  {% endif %}
  {% set ns.totalprecipitation = ns.totalprecipitation + precipitation %}
{% endfor %}
{{ ns.totalprecipitation |  float(0) | round(2) }}