-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcalculator.py
41 lines (38 loc) · 1.21 KB
/
calculator.py
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
40
41
# from functions import*
while True:
print("use n fot exit")
op = input("choose the operator?'(+ , - , * , /)'\n")
# input operator from user
if op == 'n':
break
num1 = float(input("enter first number\n"))
# input number 1 from user
num2 = float(input("enter the second number\n"))
# input number 2 from user
def addition(num1,num2):
result = num1 + num2
print("{0} + {1} = {2}".format(num1,num2,result))
def substraction(num1,num2):
result = num1 - num2
print("{0} - {1} = {2}".format(num1,num2,result))
def multiplication(num1,num2):
result = num1 * num2
print("{0} * {1} = {2}".format(num1,num2,result))
def division(num1,num2):
if num2 == 0:
print("cant divide by zero")
else:
result = num1 / num2
print("{0} / {1} = {2}".format(num1,num2,result))
if op == '+':
addition(num1,num2)
elif op == '-':
substraction(num1,num2)
elif op == '*':
multiplication(num1,num2)
elif op == '/':
division(num1,num2)
else:
print("invalid number")
print("thanks for using python calculator")
print("\n")