Skip to content

Commit 6fd9841

Browse files
authored
Python way of shortening a simple task
1 parent 5b66f3c commit 6fd9841

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

Lambdas.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
2+
add = lambda a,b : a + b
3+
sub = lambda a,b : a - b
4+
div = lambda a,b : a / b
5+
mul = lambda a,b : a *b
6+
7+
map = {"+":add, '-':sub, '*':mul,'/':div}
8+
9+
try:
10+
x = eval(input("Enter the value of x : "))
11+
y = eval(input("Enter the value of y : "))
12+
operation = input("Enter the operation [+,-,*,/] : ").strip() # remove any extra space
13+
14+
try:
15+
print(map[operation](x,y))
16+
except KeyError:
17+
print("Impossible operation")
18+
except ZeroDivisionError:
19+
print("Can't Divide by Zero")
20+
except ValueError:
21+
print("Enter numbers only")

0 commit comments

Comments
 (0)