Inkhmer LogoInKhmerBuilding the digital future
  • About
  • Projects
  • Blog
  • Tools
  • Learn
  • Contact
KMខ្មែរENEnglish

InKhmer.com — a personal Khmer Digital Hub curated by our team. Tools, Cambodia resources, Khmer culture, and digital projects. Practical, approachable, and built for everyone.

Social

FacebookTelegram

Quick Links

  • About
  • Projects
  • Blog
  • Tools
  • Learn
  • Contact

Explore

  • What We Build
  • How We Build
  • Roadmap
  • Experiments
  • Sitemap

Subscribe to our newsletter

Get the latest updates about Cambodia, new tools, and exclusive content delivered to your inbox.

  • Terms of Service
  • Privacy Policy
  • Cookie Policy

© 2026 InKhmer. All rights reserved.

LearnPython for AI and Data in KhmerLoops and functions

Loops and functions

Data work is repetitive: for every row, for every product. A loop repeats automatically, and a function lets you call the same code again.

for loop — act on each item:

for price in [20000, 12000, 8000]:
    usd = price / 4100
    print(price, "→", round(usd, 2))

if — decide:

if price > 10000:
    print("ថ្លៃ")
else:
    print("ថោក")

function — code you call again:

def to_usd(khr, rate=4100):
    return khr / rate

to_usd(20000)     # ~4.88
to_usd(12000)     # ~2.93

A real workflow: read a row, compute, add:

total = 0
for row in rows:
    total += row["price_khr"] * row["qty"]

Takeaways:

  • for = repeat; if = decide; def = call again
  • Counting starts at 0; code inside a loop is indented
  • A function makes code reusable and readable

Sign in to start tracking from this lesson