-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCalculator.py
More file actions
39 lines (35 loc) · 1.12 KB
/
Calculator.py
File metadata and controls
39 lines (35 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# Simple Python Calculator
def operation(a, b, c):
if c == '+':
print(f'\nSum of {a} and {b} is {a+b}')
elif c == '-':
print(f'\nDifference of {a} and {b} is {a-b}')
elif c == '*':
print(f'\nProduct of {a} and {b} is {a*b}')
elif c == '/':
if b == 0:
print("\nError: Cannot divide by zero, Try again")
Calculator()
else:
print(f'\nQuotient of {a} and {b} is {a/b}')
elif c == '%':
if b == 0:
print("\nError: Cannot find the remainder of a division by zero, Try again")
Calculator()
else:
print(f'\nRemainder of {a} and {b} is {a%b}')
elif c == '**':
print(f'\n{a} to the power of {b} is {a**b}')
else:
print("\nInvalid operator. Please try again.")
Calculator()
def Calculator():
a = int(input('\nEnter 1st number: '))
b = int(input('Enter 2nd number: '))
c = str(input('Enter the operator: '))
operation(a,b,c)
Calculator()
i = str(input("\nWant to continue? (y/n) \n"))
while i=="y":
Calculator()
i = str(input("\nWant to continue? (y/n) \n"))