{
  "format": "tokbit",
  "version": 1,
  "name": "Average in words",
  "main": [
    {
      "id": "u1",
      "kind": "declare",
      "name": "count",
      "type": "int"
    },
    {
      "id": "u2",
      "kind": "input",
      "target": "count",
      "prompt": "How many grades do you have?"
    },
    {
      "id": "u3",
      "kind": "declare",
      "name": "grades",
      "type": "list[int]",
      "init": "[]"
    },
    {
      "id": "u4",
      "kind": "for",
      "variable": "i",
      "range": "count",
      "body": [
        {
          "id": "u5",
          "kind": "declare",
          "name": "z",
          "type": "int"
        },
        {
          "id": "u6",
          "kind": "doWhile",
          "body": [
            {
              "id": "u7",
              "kind": "input",
              "target": "z",
              "prompt": "Grade (1 to 5):"
            }
          ],
          "condition": "z < 1 or z > 5",
          "comment": "Asks again until the grade is 1 to 5."
        },
        {
          "id": "u8",
          "kind": "call",
          "call": "grades.append(z)"
        }
      ]
    },
    {
      "id": "u9",
      "kind": "if",
      "condition": "len(grades) > 0",
      "then": [
        {
          "id": "u10",
          "kind": "declare",
          "name": "total",
          "type": "int",
          "init": "0"
        },
        {
          "id": "u11",
          "kind": "for",
          "variable": "i",
          "range": "len(grades)",
          "body": [
            {
              "id": "u12",
              "kind": "assign",
              "target": "total",
              "value": "total + grades[i]",
              "comment": "In Python the same can be written as sum(grades)."
            }
          ]
        },
        {
          "id": "u13",
          "kind": "declare",
          "name": "average",
          "type": "float",
          "init": "total / len(grades)"
        },
        {
          "id": "u14",
          "kind": "output",
          "values": "\"The average is\", round(average, 2)"
        },
        {
          "id": "u15",
          "kind": "if",
          "condition": "average <= 1.5",
          "then": [
            {
              "id": "u16",
              "kind": "output",
              "values": "\"Excellent!\""
            }
          ],
          "else": [
            {
              "id": "u17",
              "kind": "if",
              "condition": "average <= 2.5",
              "then": [
                {
                  "id": "u18",
                  "kind": "output",
                  "values": "\"Good.\""
                }
              ],
              "else": [
                {
                  "id": "u19",
                  "kind": "output",
                  "values": "\"Work harder.\""
                }
              ]
            }
          ]
        }
      ],
      "else": [
        {
          "id": "u20",
          "kind": "output",
          "values": "\"No grades.\""
        }
      ],
      "comment": "With no grades we would divide by zero."
    }
  ],
  "functions": [],
  "comment": "Solution to the task “In words”: Add a word by the average: up to 1.5 “excellent”, up to 2.5 “good”, otherwise “work harder”."
}
