-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCalculator.py
More file actions
40 lines (36 loc) · 1.29 KB
/
Calculator.py
File metadata and controls
40 lines (36 loc) · 1.29 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
print('welcome to the calculator')
def calculatorFun(num1,num2,operation):
if operation == '+':
result = num1 + num2
return num1, '+', num2, '=', result
elif operation == '-':
result = num1 - num2
return num1, '-', num2, '=', result
elif operation == '*':
result = num1 * num2
return num1, '*', num2, '=', result
elif operation == '/':
if num2 != 0:
if num2 != 0:
result = num1 / num2
return num1, '/', num2, '=', result
else:
return 'Error: Division by zero is not allowed.'
else:
return 'Invalid operation'
while True:
print('Do you want to perform another operation? (yes/no)')
choice = input('Choice: ').lower()
if choice == 'yes':
print('please enter first number . ')
num1=float(input('Number 1: '))
print('please enter opperation you want to perform (+,-,*,/): ')
operation=input('Operation: ')
print('please enter second number . ')
num2=float(input('Number 2: '))
print(calculatorFun(num1,num2,operation))
elif choice == 'no':
print('Thank you for using the calculator!')
break
else:
print('Invalid choice. Please enter yes or no.')