-
Notifications
You must be signed in to change notification settings - Fork 6.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #52 from panchadeep/master
Created a new Calculator program using Python
- Loading branch information
Showing
2 changed files
with
32 additions
and
1 deletion.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
class Calculator: | ||
def addition(self,x,y): | ||
return x+y | ||
def subtraction(self,x,y): | ||
return x-y | ||
def multiplication(self,x,y): | ||
return x*y | ||
def division(self,x,y): | ||
if y==0: | ||
return "not valid (Denominator is 0)" | ||
return x/y | ||
c=Calculator() | ||
flag="Y" | ||
while flag=="Y" or flag=="y": | ||
print("1)Addition\n2)Subtraction\n3)Multiplication\n4)Division\n") | ||
choice=int(input("Enter the operator from above: ")) | ||
a,b=input("Enter two operands seperated by space : ").split() | ||
a=int(a) | ||
b=int(b) | ||
if choice==1: | ||
print(f"Sum is {c.addition(a,b)}") | ||
elif choice==2: | ||
print(f"Difference is {c.subtraction(a,b)}") | ||
elif choice==3: | ||
print(f"Product is {c.multiplication(a,b)}") | ||
elif choice==4: | ||
print(f"Division is {c.division(a,b)}") | ||
else: | ||
print("Please enter correct input") | ||
flag=input("\nTo calculate again enter 'Y' or enter any key to exit : ") |
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