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 …
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.
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
.
This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.