Skip to content

Commit fa29b2e

Browse files
authored
Add files via upload
1 parent 42aad4c commit fa29b2e

1 file changed

Lines changed: 48 additions & 0 deletions

File tree

calculator-simple.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
def calculate():
2+
operation = input('''
3+
Please type in the math operation you would like to complete:
4+
+ for addition
5+
- for subtraction
6+
* for multiplication
7+
/ for division
8+
''')
9+
10+
number_1 = int(input('Please enter the first number: '))
11+
number_2 = int(input('Please enter the second number: '))
12+
13+
if operation == '+':
14+
print('{} + {} = '.format(number_1, number_2))
15+
print(number_1 + number_2)
16+
17+
elif operation == '-':
18+
print('{} - {} = '.format(number_1, number_2))
19+
print(number_1 - number_2)
20+
21+
elif operation == '*':
22+
print('{} * {} = '.format(number_1, number_2))
23+
print(number_1 * number_2)
24+
25+
elif operation == '/':
26+
print('{} / {} = '.format(number_1, number_2))
27+
print(number_1 / number_2)
28+
29+
else:
30+
print('You have not typed a valid operator, please run the program again.')
31+
32+
# Add again() function to calculate() function
33+
again()
34+
35+
def again():
36+
calc_again = input('''
37+
Do you want to calculate again?
38+
Please type Y for YES or N for NO.
39+
''')
40+
41+
if calc_again.upper() == 'Y':
42+
calculate()
43+
elif calc_again.upper() == 'N':
44+
print('See you later.')
45+
else:
46+
again()
47+
48+
calculate()

0 commit comments

Comments
 (0)