Hack Forums
[Python] Hackerrank Python Help - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [Python] Hackerrank Python Help (/showthread.php?tid=5683674)



Hackerrank Python Help - mutybyte - Aug 1, 2017

Here is the link --->
https://www.hackerrank.com/challenges/exceptions

I tried this code

Code
try:
    a = int(input())
    b = int(input())
    print(a/b)
except(ZeroDivisionError or ValueError) as e:
    print("Error Code", e)

There output in website is ->
PHP Code

<?php 
Your code did not pass this test 
case.
Input (stdin)
3
1 0
2 
$
3 1
Your Output 
(stdout)
~ 
no response on stdout ~

Expected Output
Error Code
: integer division or modulo by zero
Error Code
: invalid literal for int() with base 10: '$'
3
Compiler Message
Runtime Error
Error 
(stderr)
Traceback (most recent call last):
  
File "solution.py", line 3, in <module>
    
b = int(input())
ValueError: invalid literal for int() with base 10: '1 0\r' 

What i do wrong


* - mutybyte - Aug 1, 2017

Same result check error there expecting output and mine output none in there's my output


* - Consulting Detective - Aug 1, 2017

(Aug 1, 2017 01:45 AM)mutybyte Wrote:  Same result check error there expecting output and mine output none in there's my output

try this.
Code
try:
    a = int(input())
    b = int(input())
    print(a/b)
except Exception as e:
    print("Error Code", e)