Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e48510f

Browse files
Add files via upload
1 parent 9c11ee1 commit e48510f

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

22-Calculator.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
2+
def calc(x, y, ops):
3+
"""
4+
Returns a string like this: a op b = c
5+
where c is the computed value according to the opeartor
6+
"""
7+
8+
if ops not in '+-/*':
9+
return 'Please only type one of these characters: "+, -, *, /"!'
10+
11+
if ops == '+':
12+
return(str(x) + ' ' + ops + ' ' + str(y) + ' = ' + str(x + y))
13+
if ops == '-':
14+
return(str(x) + ' ' + ops + ' ' + str(y) + ' = ' + str(x - y))
15+
if ops == '*':
16+
return(str(x) + ' ' + ops + ' ' + str(y) + ' = ' + str(x * y))
17+
if ops == '/':
18+
return(str(x) + ' ' + ops + ' ' + str(y) + ' = ' + str(x / y))
19+
20+
while True:
21+
22+
x = int(input('Please type the first number: '))
23+
y = int(input('Please type the second number: '))
24+
ops = input("Choose between +, -, *, / ")
25+
26+
print(calc(x, y, ops))
27+

0 commit comments

Comments
 (0)