-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcalc.py
32 lines (22 loc) · 807 Bytes
/
calc.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
# Calculator
# Basic calculator using "+, -, *, /"
def calc(a, b, op):
if op not in '+-/*':
return 'Please enter these: "+, -, *, /"!'
if op == '+':
return(str(a) + ' ' + op + ' ' + str(b) + ' = ' + str(a + b))
if op == '-':
return(str(a) + ' ' + op + ' ' + str(b) + ' = ' + str(a - b))
if op == '*':
return(str(a) + ' ' + op + ' ' + str(b) + ' = ' + str(a * b))
if op == '/':
return(str(a) + ' ' + op + ' ' + str(b) + ' = ' + str(a / b))
def main():
a = int(input('Please type the first number: '))
b = int(input('Please type the second number: '))
op = input(
'What kind of operation would you like to do?\
\nChoose between "+, -, *, /" : ')
print(calc(a, b, op))
if __name__ == '__main__':
main()