Download kiosk.txt from the banner and Add files, or let the first block create it.
Goal
Read kiosk.txt and print each city and amount.
from pathlib import Path
Path("kiosk.txt").write_text(
"2026-01-12 Nairobi 126.0\n2026-01-13 Kisumu 62.0\n",
encoding="utf-8",
)
print(Path("kiosk.txt").read_text(encoding="utf-8"))from pathlib import Path
import re
text = Path("kiosk.txt").read_text(encoding="utf-8")
for m in re.finditer(r"(?P<date>\S+) (?P<city>\w+) (?P<kes>[\d.]+)", text):
print(m.groupdict())from pathlib import Path
import re
text = Path("kiosk.txt").read_text(encoding="utf-8")
print(re.findall(r"Nairobi .*", text))from pathlib import Path
import re
text = Path("kiosk.txt").read_text(encoding="utf-8")
print(sum(float(x) for x in re.findall(r"[\d.]+$", text, re.M)))