Activity of Making a Python Calculator

# Activity of Making a Python Calculator

##### Lesson Details:
July 10, 2020

I: Introduction

In this article I will be explaining the coding languages and how they are used to make a calculator. Programming languages have been around for a long time. They were created to write programs that will execute a set of instructions. These programs or codes can then be used to do or create a variety of things. The language is a way to communicate with another person or a machine. Each programming language has a specific syntax, meaning it follows a specific order of doing things. In this article I will specifically be talking about Python which is a coding language.

I: Body

In the body I will be explaining how to make a calculator using python programming language. Making a calculator can be done easily with python. The code for this program will not be very hard at all. You can find out more about python at https://www.python.org/doc/. To make a calculator you will need a few things to help you. First you will need a computer which can be found in most places these days. Next you will need the programming language which will also be called python. Python can be downloaded onto your computer from the web site listed above. The next thing you will need is some paper to write down your calculations on. The last thing you will need is some money to buy some batteries for your calculator.

A: Making the Calculator

To start off making the calculator you will need to type up the program on paper if you are typing on your computer. The first step is to put in the following code:

The first line is just stating what kind of program it is, in this case it is an action program. Next we have the function definition, which tells the computer what the program does. The next line contains the option of whether or not you want to show the command prompt on the screen, in this case we want to show it on the screen. Next we have the standard input output format, which tells the computer how to read and write data to files. The next line tells us that this calculation program will read data from the standard input file and write data to the standard output file. Next we have our string of commands, which is where we enter the instructions for our program, for example if we wanted to add two numbers together we would do something like this:

print (“Please enter 2 numbers separated by spaces”)

num1 = int(input())

num2 = int(input())

total = num1 + num2

print(“The total of ” + str(num1) + ” and ” + str(num2) + ” is ” + str(total))

The next line is simply our print statement. This is where we may want to print out reports or any other important information to use in our program. This line also has an added option of inserting the current time stamp into our print statement, so it looks like this with the time stamp included:

print (“Please enter 2 numbers separated by spaces”, end=” “)

num1 = int(input())

num2 = int(input())

total = num1 + num2

print(str(strftime()), “The total of ” + str(num1) + ” and ” + str(num2) + ” is ” + str(total))

Next we have our main function, which tells the computer what our program actually does with its inputs. Our main function looks like this:

def main():

print(“Please enter 2 numbers separated by spaces”)

num1 = int(input())

num2 = int(input())

total = num1 + num2

print(str(strftime()), “The total of ” + str(num1) + ” and ” + str(num2) + ” is ” + str(total)) 