Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
calculator-class-exercise/calculator.py
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
53 lines (40 sloc)
1.36 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Python program for simple calculator | |
# https://www.geeksforgeeks.org/make-simple-calculator-using-python/ | |
# Function to add two numbers | |
def add(num1, num2): | |
return num1 + num2 | |
# Function to subtract two numbers | |
def subtract(num1, num2): | |
return num1 - num2 | |
# Function to multiply two numbers | |
def multiply(num1, num2): | |
return num1 * num2 | |
# Function to divide two numbers | |
def divide(num1, num2): | |
return num1 / num2 | |
def run_calc(): | |
print("Please select operation -\n" \ | |
"1. Add\n" \ | |
"2. Subtract\n" \ | |
"3. Multiply\n" \ | |
"4. Divide\n") | |
# Take input from the user | |
select = int(input("Select operations form 1, 2, 3, 4 :")) | |
number_1 = int(input("Enter first number: ")) | |
number_2 = int(input("Enter second number: ")) | |
if select == 1: | |
print(number_1, "+", number_2, "=", | |
add(number_1, number_2)) | |
elif select == 2: | |
print(number_1, "-", number_2, "=", | |
subtract(number_1, number_2)) | |
elif select == 3: | |
print(number_1, "*", number_2, "=", | |
multiply(number_1, number_2)) | |
elif select == 4: | |
print(number_1, "/", number_2, "=", | |
divide(number_1, number_2)) | |
else: | |
print("Invalid input") | |
if __name__ == "__main__": | |
run_calc() |