-
Notifications
You must be signed in to change notification settings - Fork 0
/
calculate.py
34 lines (27 loc) · 1.18 KB
/
calculate.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
def calculate(num1, num2, operation):
if operation ==1:
answer = str(num1) + ' + ' + str(num2) +' = '+ str(num1 + num2)
elif operation == 2:
answer = str(num1) + ' - ' + str(num2) +' = '+ str(num1 - num2)
elif operation == 3:
answer = str(num1) + ' x ' + str(num2) +' = '+ str(num1 * num2)
elif operation == 4:
answer = str(num1) + ' / ' + str(num2) +' = '+ str(num1 / num2)
elif operation == 5:
answer = str(num1) + ' ^ ' + str(num2) +' = '+ str(num1 ** num2)
elif operation == 6:
answer = str(num1) + ' ^ (1/' + str(num2) +') = '+ str(num1**(1/num2))
else:
answer= 'UNKNOWN OPERATION'
return answer
while True:
num1 = int(input('Enter a number: '))
num2 = int(input('Enter another number: '))
print("Operations to carry out \n Addition = 1 \n Subtraction= 2, \n multiplication = 3, \n, Division = 4,\n Exponential =5,\n root= 6")
operation = int(input('Enter operation: '))
print(calculate(num1, num2, operation))
q= input('Do you want to continue: ')
q = q.lower()
if q != 'yes' and q != 'y':
print('Thank you for using the program')
break