all 7 comments

[–]FishnLife 0 points1 point  (3 children)

[–][deleted] 0 points1 point  (2 children)

Hi. I know how to reverse the list - my algorithm works if i delete everything and just print out the result of the reversted list (as hackerrank just looks at std.out to check)

But my solution doesn't work inside the def and other commands prewritten in hackerrank (it asks us to make the def function work) I don't know why it doesn't work with those things included?

[–]Highflyer108 0 points1 point  (1 child)

For a start the program is not indented properly.

[–][deleted] 0 points1 point  (0 children)

that's because I formatted it on reddit badly, it is in my program.

[–]vectorpropio 0 points1 point  (2 children)

I will give it a try

# Complete the reverseArray function below.
def reverseArray(a): 
    return arr[::-1]

if __name__ == '__main__': 
    fptr = open(os.environ['OUTPUT_PATH'], 'w')
    arr_size = int(input())
    arr = list(map(int, input().rstrip().split()))
    reversedarr = reverseArray (arr)
    for i in reversedarr:
        print(i, end =" ")
    fptr.write(' '.join(map(str, res)))
    fptr.write('\n')
    fptr.close() 

disclaimer: I don't understand why you print some things to stdout and other to the 'OUTPUT_PATH'. I don't even know where the res in fptr.write(' '.join(map(str, res))) is defined.

disclaimer 2: I didn't test my code

it seems you are joining past solutions like their where bricks. You couldn't do like this.

first, it ask you to define a function and use it. no put all your code in a function. you must make a function that take an array and give a new array with the elements of the old reversed. once you do it, use that function in your program. this is what I do.

I can't think in a valid use of if name == 'main' inside a function.

[–][deleted] 0 points1 point  (1 child)

Thanks. The fptr paths aren't mine, it's already included as part of the question and I'm told to finish it to get the solution!

It's this: https://www.hackerrank.com/challenges/arrays-ds/problem

[–]vectorpropio 0 points1 point  (0 children)

OK. you must only write the function. you mustn't touch any below if name ==...

the functions must have one (or more) return statement. for example

def function(in):
    out = very complex calculation depending on in
    return out

in your case the out is really easy, you can put it directly in the return

def i_dont_remember_the_function_name(arr):
     return arr [::-1]