Python program to add two integers with handling expectations
try:
k=int(input("Enter First Value: "))
j=int(input("Enter Second Value: "))
d=k/j
print(d)
except ValueError as e:
print('Pls Input Integer Only',e)
except ZeroDivisionError as e:
print('Second Number Should Not Be Zero',e)
except Exception as e:
print('Other Error',e)
Output:
RUN 1:
Enter First Value: 10
Enter Second Value: 20
0.5
RUN 2:
Enter First Value: 10
Enter Second Value: Hello
Pls Input Integer Only invalid literal for int() with base 10: 'Hello'
RUN 3:
Enter First Value: 10
Enter Second Value: 0
Second Number Should Not Be Zero division by zero
Python program to add two integers with handling expectations
Output:
need an explanation for this answer? contact us directly to get an explanation for this answer