-
Notifications
You must be signed in to change notification settings - Fork 0
/
simple calculator.py
55 lines (37 loc) · 1.05 KB
/
simple 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
def calculate():
a = float(input("Enter the first number: "))
b = float(input("Enter the second number: "))
operations = ['+', '-', '*', '/']
operation = input('''
+ for addition
- for subtraction
* for multiplication
/ for division
''')
if operation == '+':
print('{} + {} = '.format(a, b))
print(a + b)
elif operation == '-':
print('{} - {} = '.format(a, b))
print(a - b)
elif operation == '*':
print('{} * {} = '.format(a, b))
print(a * b)
elif operation == '/':
print('{} / {} = '.format(a, b))
print(a / b)
else:
print('You have not typed a valid operator, please run the program again.')
def again():
calc_again = input('''
Do you want to calculate again?
Please type Y for YES or N for NO.
''')
if calc_again.upper() == 'Y':
calculate()
elif calc_again.upper() == 'N':
print('See you later.')
else:
again()
calculate()
again()