Skip to main content
Skip to content

Math · Beginner

Calculator Program in Hindi Programming

One function, four operations, and a guard against dividing by zero.

The program

Edit anything and press Run. The output below was produced by running this exact code.

Expected output

Press Run to try it

12 + 4 = 1612 - 4 = 812 * 4 = 4812 / 4 = 312 / 0 = Zero se divide nahi kar sakte12 ^ 4 = Ye operation samajh nahi aaya: ^

How it works

calculate(a, op, b) takes two numbers and the operation as text. A warna agar chain compares op with each symbol and lautao returns the matching result straight away.

Division gets an extra check: AltFLang stops a program that divides by zero, so the function returns a message instead of attempting it. Anything that is not one of the four symbols falls through to the last line, which joins a message and the unknown symbol with +.

Because the function returns values rather than printing them, the same function can feed a bigger program — a bill, a quiz, or the input-driven calculator you build after the pucho lesson.