interplane.Get Omega
Read in your language

aienux

Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately.

Brought by drakestapleton

branch main Branches Tags History

aienux / native / kernel / svc / tests / fixtures / code / short.txt

33 lines · 844 bytes Raw Blame History
1Here is a small calculator you can run with python3 calc.py.
2
3```python
4# calc.py: a small calculator that reads one sum at a time.
5import operator
6
7OPS = {"+": operator.add, "-": operator.sub, "*": operator.mul, "/": operator.truediv}
8
9
10def calculate(a, op, b):
11 if op not in OPS:
12 raise ValueError("unknown operator " + op)
13 if op == "/" and b == 0:
14 raise ZeroDivisionError("cannot divide by zero")
15 return OPS[op](a, b)
16
17
18def main():
19 print("Type a sum like 3 + 4, or q to quit.")
20 while True:
21 line = input("> ").strip()
22 if line in ("q", "quit"):
23 break
24 try:
25 a, op, b = line.split()
26 print(calculate(float(a), op, float(b)))
27 except (ValueError, ZeroDivisionError) as e:
28 print("Sorry:", e)
29
30
31if __name__ == "__main__":
32 main()
33```