1
Home
Tirsvad edited this page 2026-11-15 10:05:06 +01:00

English · Dansk · Bahasa Melayu

Calculator

A console calculator: pick two numbers and an operation, then keep calculating with the result.

What is it?

Day 10 of the Udemy course 100 Days of Code: The Complete Python Pro Bootcamp. The program shows an ASCII calculator and asks for a number, an operation (+, -, *, /) and a second number. The operations are functions stored in a dictionary and called through it. After each result you can continue with it, start a new calculation (the program calls itself again, which is recursion) or quit.

What the exercise teaches

  • Writing small functions with parameters and return values
  • Storing functions in a dictionary and calling them through it
  • Looping until the input is valid, and restarting a program with recursion
  • Keeping texts in constants and writing small automated tests

What it does

  • Addition, subtraction, multiplication and division of two numbers
  • Continue with the previous result (y), start anew (n) or quit (q)
  • Invalid numbers, operations and answers are asked for again with a friendly message
  • Dividing by zero shows a message and starts a new calculation

Next