Leonidus
Leonidus

Reputation: 448

Run Time Error Exited with error status 1

The problem is this : I tried to solve it and I think I did too but when I mailed it for evaluation it says

We have tested your solution, and while doing so we unfortunately
discovered the following error:
Run Time Error

Exited with error status 1

Here is my code :

import re
import sys
def fun():
    for ind in ratio:
        max_num = ratio_list[0]
        if ratio[ind] == max_num:
            print ind

    ratio_list.remove(ratio_list[0])

hits = []
song = []   
n,m = raw_input().split(' ',1)


for i in range(0,int(n)):
    h,n = raw_input().split(" ",1)

    is_number = isinstance( int(h), int )   
    is_string = len(n)<=30 and bool(re.match('[a-z_0-9]+$', n))
    if not(is_number and is_string):
        sys.exit("Error");
    hits.append(int(h))
    song.append(n)
ratio = {}
ratio_list = []
f_of_i = hits[0]
counter = 1
index = 0

for hit in hits:
    ratio_list.append(hit*counter)
    ratio[song[index]] = hit*counter
    index = index +1
    counter = counter +1

ratio_list.sort()
ratio_list.reverse()

for j in range(0,int(m)):
    fun()

What am I doing wrong ? I am curious why the solution is unacceptable killing me.

Upvotes: 3

Views: 8468

Answers (1)

NPE
NPE

Reputation: 500437

I suspect you're hitting

    sys.exit("Error");

As explained in the documentation:

Some systems have a convention for assigning specific meanings to specific exit codes, but these are generally underdeveloped; Unix programs generally use 2 for command line syntax errors and 1 for all other kind of errors. If another type of object is passed, None is equivalent to passing zero, and any other object is printed to stderr and results in an exit code of 1.

Might be worth relaxing your input validation a little? Right now it's so strict it would reject inputs that to me appear within the spec (say if there were two spaces between the play count and the song title).

Another possibility is that your code raises an exception. On my machine this also results in an exit code of 1.

Finally, while not a bug, I think the way you reuse the variable called n is questionable style.

Upvotes: 4

Related Questions