Let's begin!
Creating a basic calculator is a no biggie! So we are applying the concept of object oriented programming and making this program work until the user ask to end the task, in this calculator we can also intake the value as much as we want without restarting the program!
It's one of basis and yet a core project where majority of your programming skills are used!
Happy Programming!
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
class Binary_Calculator: | |
def sum(a, b): # Function to add | |
return a + b | |
def pro(a, b): # Function to multiply | |
return a * b | |
def sub(a, b): # Function to subtract | |
return a - b | |
def div(a, b): # Function to divide | |
return a / b | |
a=int(input("Please input the first number: ")) #Take input in integer for first number | |
b=int(input("Please input the second number: "))#Take input in integer for second number | |
x=6 #Creating a variable and providing a value to initialise loop | |
while x!=0: #Condition to terminate the loop | |
x = int(input("Please input the operation\n1 for Addition\n2 for Subtraction\n3 for Multiplication\n4 for Division\n5 to Change the Input\n0 to Exit\n")) #Conditions for Calculatot Operation Guidelines | |
if x == 1: | |
print("Result: ",Binary_Calculator.sum(a, b)) #Calling function to add | |
elif x == 2: | |
print("Result: ",Binary_Calculator.sub(a, b)) #Calling function to subtract | |
elif x == 3: | |
print("Result: ",Binary_Calculator.pro(a, b)) #Calling function to multiply | |
elif x == 4: | |
print("Result: ",Binary_Calculator.div(a, b)) #Calling function to divide | |
elif x== 5: #Condition to reinitialise the value | |
a = int(input("Please input the first number: ")) | |
b = int(input("Please input the second number: ")) | |
elif x== 0: #Condition to terminate the loop | |
print('Good Bye!') | |
else: #For any other input | |
print('Wrong Input') |
Comments
Post a Comment