Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

Python 

Hackerrank Python Help

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
Same result check error there expecting output and mine output none in there's my output
(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)


Possibly Related Threads...
Thread / Author Replies Views Last Post
[Python] by AzythumAug 2, 2024 10:19 AM 3 189 Aug 2, 2024 10:19 AM
Last Post: Perlo
[Python] by Bass_ReevesAug 20, 2023 01:44 AM 9 632 Aug 20, 2023 01:44 AM
Last Post: Lucky4L
[C] by MelonbreadHFNov 4, 2018 01:44 AM 0 161 Nov 4, 2018 01:44 AM
Last Post: MelonbreadHF