# 4) Write a program to input two number from the user and handle your exception using else

a = int(input("value of A : "))
b = int(input("value of B : "))
c = a+b
if c == a+b :
      print("Answer :",c)
else:
    print("something wrong")

i using that code but in that i not able to print else part . when i give string value …

It would be good if you provide some more information.

You are not able to get the else part when you give a string value because you are converting the a and the b values into an integer.

4) Write a program to input two number from the user and handle your exception using else.

i m doing that think . in we used int value but if we give string than i think to print else part on

i just wanna check given values are int or not and if value is int than print answer and given value not int than print i wanna print else part .
so pls help for that

You can use the try…except statement

//Sample
try:
  print(a)
except:
  print("An exception occurred")

You need not use the variable c
Within the try block you can print the int of a plus the int of b.

1 Like