Python Calculator Project!

In this project we're gonna show you how to make a simple calculator on python!

Requirements & Introduction

First we're gonna need to download Python latest version for this project, an IDE of your choice (i prefer VSCode) and you're ready! This project is for beginners who are trying to learn more about python, it has functions, operations and more!

1° Step

We're gonna import the library for this project, os is for clearing the screen after a specific code for it to look clean.

import os

2° Step

Now we define the functions for the operations

def add(x, y):
    resultado = (x + y)
    guardar_archivo(str(resultado))
    return resultado

def substract(x, y):
    return x - y

def multiply(x, y):
    return x * y

def divide(x, y):
    return x / y

def potencial(x, y):
    return x ** y

def pregunta():
    input('Press ENTER to new operation')

3° Step

Now we define our menu for the calculator:

def menu():
    os.system('cls')
    print("Jorge's Calculator")
    print("1. Add")
    print("2. Substract")
    print("3. Multiply")
    print("4. Divide")
    print("5. Power")

4° Step

We add the inputs, one were we ask for what kind of operation we want to do and the other on were we ask 2 number for the operations:

choice = input("Let's calculate something today, shall we? Please choose one number 1,2,3,4,5!: ")
num1 = int(input("Enter the first number: "))
num2 = int(input("Enter the second number: "))

5° Step

We add conditions were we see what choice did the user made:

    if choice == "1":
        print(num1, "+",num2,"=", add(num1,num2))
        pregunta()
        menu()
    elif choice == "2":
        print(num1, "-",num2,"=", substract(num1,num2))
        pregunta()
        menu()
    elif choice == "3":
        print(num1, "*",num2, "=", multiply(num1,num2))
        pregunta()
        menu()
    elif choice == "4":
        print(num1, "/",num2, "=", divide(num1,num2))
        pregunta()
        menu()
    elif choice == "5":
        print(num1, "**",num2, "=", potencial(num1,num2))
        pregunta()
        menu()
    else:
        print("Invalid Input")

6° Step

We now call the menu function.

menu()

input('Press ENTER to exit')

Full Code

I'll leave right here the code from my github, so you can take a good look at it!

Github Code