-
Notifications
You must be signed in to change notification settings - Fork 0
/
cal5.py
59 lines (55 loc) · 1.58 KB
/
cal5.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#calculator program
#add
def add_num(x, y):
sum = x + y
return sum
#subtract
def subtract_num(x, y):
subtract = x - y
return subtract
#multiply
def multiply_num(x, y):
multiply = x * y
return multiply
#divide
def divide_num(x, y):
if y == 0:
print("Cannot divide by 0")
else:
divide = x / y
return divide
#main function
def main_func():
x = 1
while x > 0:
#get user input
user_input = input("Enter 'e' to exit and 'c' to calculate: ")
if user_input == 'e' or user_input == 'E':
print("Thank you")
break
elif user_input == "c" or user_input == 'C':
num1 = float(input("Enter first number: "))
num2 = float(input("Enter second number: "))
operation = input("enter operation + - / *: ")
if operation == "+":
result = add_num(num1, num2)
print("Sum is " ,result)
print("")
elif operation == "-":
result = subtract_num(num1, num2)
print("Difference is" ,result)
print("")
elif operation == "*":
result = multiply_num(num1, num2)
print("Product is" ,result)
print("")
elif operation == "/":
result = divide_num(num1, num2)
print("Quotient is" ,result)
print("")
else:
print("invalid operation")
else:
print('press either e or c')
x += 1
main_func()