Skip to content
This repository was archived by the owner on Aug 20, 2024. It is now read-only.

add try-except cluase for sum.py #149

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 16 additions & 9 deletions Python/PythonBasics/sum.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
a = int(input("Enter 1st Number"))
b = int(input("Enter 2st Number"))
c = a + b

if c <= 20 :
print("no operation performed")
elif c > 20 and c <= 40 :
print("product is ",(a*b))
elif c > 40 and c <= 60 :
print("difference is ",(a-b))
else :
print("sum is ",c)
try:
## make sure if a, b are number
for e in [a, b]:
assert type(e) in [int, float]
c = a + b

if c <= 20 :
print("no operation performed")
elif c > 20 and c <= 40 :
print("product is ",(a*b))
elif c > 40 and c <= 60 :
print("difference is ",(a-b))
else :
print("sum is ",c)
except:
print("invalid input")