Python Forum
This code gives error on website but none on my editor
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
This code gives error on website but none on my editor
#1
I was doing a challenge on hacker rank about doing arrays in python. I really didn't know how to do arrays because I have not read about it. But I read about the function that was recommended by the website and tried something based on the function documentation, map. I tried the code below. The code worked fine on my editor, vs code, but it gave a runtime error on the hacker rank website. Can someone please go through it and tell me why it gave a run time error on the website.
The code is to ask a user to create an array of n items and to print the items of the array in reverse order.
In my implementation, because I did not know much about arrays, I took the elements of the array and put them into a list object, and then reversed the list. Cool on my editor but run time error on the website. Please, I need help.
#!/bin/python3

import math
import os
import random
import re
import sys



if __name__ == '__main__':
    n = int(input())
    vis = 0
    dlist = list()
    while vis < n :
        arr = list(map(int, input().rstrip().split()))
        for i in arr : 
            dlist.append(i) 
        vis += 1
    #i have the list
    #print it in reversed order
    for i in dlist[::-1] :
        print(i, end=' ')
The output of the error is:
Output:
Traceback (most recent call last): File "Solution.py", line 16, in <module> arr = list(map(int, input().rstrip().split())) EOFError: EOF when reading a line
Please, counting on you.
Reply
#2
I would guess it depends on what the site supply as test data and how it supply them.
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020