top of page

# How Do They Work? Calculators

### Have You Ever Wondered…

1. How does a calculator work?

2. When was the calculator invented?

3. How big were the first calculators?

4. How to make my own simple Calculator using Python Code.

### I don’t recommend you do this with your brand-new school calculator if you want to stay on speaking terms with your parents, so I’ve saved you the bother. Here’s what you’ll find inside:

1. Input: Keyboard: About 40 tiny plastic keys with a rubber membrane underneath and a touch-sensitive circuit underneath that.

2. Processor: A microchip that does all the hard work. This does the same job as all the hundreds of gears in an early calculator.

3. Output: A liquid crystal display (LCD) for showing you the numbers you type in and the results of your calculations.

4. Power source: A long-life battery (mine has a thin lithium “button” cell that lasts several years). Some calculators also have a solar cell to provide free power in the daylight. ### Press down on one of the number keys on your calculator and a series of things will happen in quick succession:

1. As you press on the hard plastic, you compress the rubber membrane underneath it. This is a kind of a miniature trampoline that has a small rubber button positioned directly underneath each key and a hollow space underneath that. When you press a key, you squash flat the rubber button on the membrane directly underneath it.

2. The rubber button pushes down making an electrical contact between two layers in the keyboard sensor underneath and the keyboard circuit detects this.

3. The processor chip figures out which key you have pressed.

4. A circuit in the processor chip activates the appropriate segments on the display corresponding to the number you’ve pressed.

5. If you press more numbers, the processor chip will show them up on the display as well—and it will keep doing this until you press one of the operations keys (such as +, −, ×, ÷) to make it do something different. Suppose you press the + key. The calculator will store the number you just entered in a small memory called a register.

6. Then it will wipe the display and wait for you to enter another number. As you enter this second number, the processor chip will display it digit-by-digit as before and store it in another register. Finally, when you hit the = key, the calculator will add the contents of the two registers together and display the result.

7. There’s a little more to it than that—and I’ll go into a few more details down below.

### How does the display work?

1. You’re probably used to the idea that your computer screen makes letters and numbers using a tiny grid of dots called pixels.

2. Early computers used just a few pixels and looked very dotty and grainy, but a modern LCD screen uses millions of pixels and is almost as clear and sharp as a printed book.

3. Calculators, however, remain stuck in the dark ages—or the early 1970s, to be precise. Look closely at the digits on a calculator and you’ll see each one is made from a different pattern of seven bars or segments.

4. The processor chip knows it can display any of the numbers 0-9 by activating a different combination of these seven segments. It can’t easily display letters, though some scientific calculators (more advanced electronic calculators with lots of built into mathematical and scientific formulae) do have a go.

### To understand this example, you should have the knowledge of the following Python programming topics:

1. Python Functions

2. Python Function Arguments

3. Python User-defined Functions

Simple Calculator by Using Functions

```# Program make a simple calculator

# This function adds two numbers
return x + y

# This function subtracts two numbers
def subtract(x, y):
return x - y

# This function multiplies two numbers
def multiply(x, y):
return x * y

# This function divides two numbers
def divide(x, y):
return x / y

print("Select operation.")
print("2.Subtract")
print("3.Multiply")
print("4.Divide")

while True:
# Take input from the user
choice = input("Enter choice(1/2/3/4): ")

# Check if choice is one of the four options
if choice in ('1', '2', '3', '4'):
num1 = float(input("Enter first number: "))
num2 = float(input("Enter second number: "))

if choice == '1':
print(num1, "+", num2, "=", add(num1, num2))

elif choice == '2':
print(num1, "-", num2, "=", subtract(num1, num2))

elif choice == '3':
print(num1, "*", num2, "=", multiply(num1, num2))

elif choice == '4':
print(num1, "/", num2, "=", divide(num1, num2))
break
else:
print("Invalid Input")```

Output
```Select operation.
2.Subtract
3.Multiply
4.Divide
Enter choice(1/2/3/4): 3
Enter first number: 15
Enter second number: 14
15.0 * 14.0 = 210.0```

Tags:

bottom of page