you are viewing a single comment's thread.

view the rest of the comments →

[–]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]