Examples
Example programs
Real kemlang-py programs you can study, copy, and run. Each example shows a self-contained concept.
Hello World
The simplest possible kemlang-py program.
jskkem bhai bhai bol "kem cho, duniya!" aavjo bhai
output
kem cho, duniya!
Personal greeting
Read the user's name and print a greeting.
jskkem bhai bhai bol "What is your name?" aa naam che bapu tame bolo bhai bol "kem cho, " + naam + "!" aavjo bhai
output
What is your name? > Sanket kem cho, Sanket!
Even or odd
Check whether a number is even or odd using modulo.
jskkem bhai aa n che 7 jo n % 2 == 0 { bhai bol n + " is even" } nahi to { bhai bol n + " is odd" } aavjo bhai
output
7 is odd
Count to N
Print numbers 1 through N using a loop.
jskkem bhai aa n che 5 aa i che 1 farvu { bhai bol i i che i + 1 } jya sudhi i <= n aavjo bhai
output
1 2 3 4 5
FizzBuzz
The classic interview problem - print Fizz, Buzz, or FizzBuzz.
jskkem bhai aa n che 1 farvu { jo n % 15 == 0 { bhai bol "FizzBuzz" } nahi to { jo n % 3 == 0 { bhai bol "Fizz" } nahi to { jo n % 5 == 0 { bhai bol "Buzz" } nahi to { bhai bol n } } } n che n + 1 } jya sudhi n <= 15 aavjo bhai
output
1 2 Fizz 4 Buzz Fizz 7 8 Fizz Buzz 11 Fizz 13 14 FizzBuzz
Sum of odd numbers
Use continue to skip even numbers and sum only the odd ones.
jskkem bhai aa sum che 0 aa i che 1 farvu { jo i % 2 == 0 { aagal vado } sum che sum + i i che i + 1 } jya sudhi i <= 10 bhai bol "Sum of odds 1-10: " + sum aavjo bhai
output
Sum of odds 1-10: 25
Number guessing game
A complete interactive game with a loop, input, and break.
jskkem bhai aa secret che 42 aa tries che 0 farvu { bhai bol "Guess (1-100):" aa guess che bapu tame bolo tries che tries + 1 jo guess == secret { bhai bol "Correct in " + tries + " tries!" tame jao } nahi to { bhai bol "Try again..." } } jya sudhi bhai chhe aavjo bhai
output
Guess (1-100): > 50 Try again... Guess (1-100): > 42 Correct in 2 tries!
Grade calculator
Assign letter grades based on a numeric score.
jskkem bhai bhai bol "Enter your score:" aa score che bapu tame bolo jo score >= 90 { bhai bol "Grade: A" } nahi to { jo score >= 80 { bhai bol "Grade: B" } nahi to { jo score >= 70 { bhai bol "Grade: C" } nahi to { jo score >= 60 { bhai bol "Grade: D" } nahi to { bhai bol "Grade: F" } } } } aavjo bhai
output
Enter your score: > 85 Grade: B
Want to run these yourself? Open the playground or install kemlang-py locally.