ValueError<\/strong><\/p>\n\n\n\nThis error is raised when a built-in operation or function receives an argument that has the right type but an inappropriate value.<\/p>\n\n\n\n
>>> a = '1'\n>>> b = '#'\n>>> print int(a) \/ int(b)\n>>> ValueError: invalid literal for int() with base 10: '#'<\/pre>\n\n\n\nHandling Exceptions<\/strong><\/p>\n\n\n\nThe statements try and except can be used to handle selected exceptions. A try statement may have more than one except clause to specify handlers for different exceptions.<\/p>\n\n\n\n
#Code\ntry:\n print 1\/0\nexcept ZeroDivisionError as e:\n print \"Error Code:\",e<\/pre>\n\n\n\nOutput<\/strong><\/p>\n\n\n\nError Code: integer division or modulo by zero<\/p>\n\n\n\n
<\/span>Task<\/strong><\/span><\/h2>\n\n\n\nYou are given two values a<\/strong><\/em> and b<\/em><\/strong>.<\/p>\n\n\n\nPerform integer division and print a \/ b<\/strong>.<\/p>\n\n\n\n<\/span>Input Format<\/strong><\/span><\/h2>\n\n\n\nThe first line contains T<\/em><\/strong>, the number of test cases.<\/p>\n\n\n\nThe next T<\/em><\/strong> lines each contain the space separated values of a<\/strong><\/em> and b<\/em><\/strong>.<\/p>\n\n\n\n<\/span>Constraints<\/strong><\/span><\/h2>\n\n\n\n0 < T < 10<\/strong><\/p>\n\n\n\n<\/span>Output Format<\/strong><\/span><\/h2>\n\n\n\nPrint the value of a <\/em>\/ b<\/em><\/strong>.<\/p>\n\n\n\nIn the case of ZeroDivisionError or ValueError, print the error code.<\/p>\n\n\n\n
Sample Input<\/strong><\/p>\n\n\n\n3\n1 0\n2 $\n3 1<\/pre>\n\n\n\nSample Output <\/strong><\/p>\n\n\n\nError Code: integer division or modulo by zero\nError Code: invalid literal for int() with base 10: '$'\n3<\/pre>\n\n\n\n<\/span>Solution – Exceptions in Python – Hacker Rank Solution<\/strong><\/span><\/h2>\n\n\n\n<\/span>Python 3<\/strong><\/span><\/h3>\n\n\n\n# Enter your code here. Read input from STDIN. Print output to STDOUT\nT = int(input())\nfor i in range(T):\n try:\n a, b = map(int, input().split())\n print(a\/\/b)\n except Exception as e:\n print(\"Error Code:\",e)<\/pre>\n\n\n\n