Python Forum

Full Version: EOFError: EOF when reading a line - Runtime Error
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi,

#!/bin/python3

import math
import os
import random
import re
import sys

def print_reverse_number(n,arr): 
    arr = []
    n = int(input())

    for i in range(0,n):
  
        element_input = int(input())

        arr.append(element_input)
        arr.reverse()
  
  

    print(arr)

if __name__ == '__main__':
    n = int(input())

    arr = list(map(int, input().rstrip().split()))

    print_reverse_number(n, arr)
Error:
Runtime Error Error (stderr) Traceback (most recent call last): File "Solution.py", line 37, in <module> print_reverse_number(n, arr) File "Solution.py", line 11, in print_reverse_number n = int(input()) EOFError: EOF when reading a line
I don't understand where is the problem with this code.

The task of challenge is this:
Given an array, A, of N integers, print A's elements in reverse order as a single line of space-separated numbers.
Regards,
RavCoder
Try putting arr.reverse() with the same spacing of print(arr) to see if that may help get you closer to your solution.

import math
import os
import random
import re
import sys
 
def print_reverse_number(n,arr): 
    arr = []
    n = int(input())
 
    for i in range(0,n):
   
        element_input = int(input())
 
        arr.append(element_input)
        
    arr.reverse() 
    print(arr)
 
if __name__ == '__main__':
    n = int(input())
 
    arr = list(map(int, input().rstrip().split()))
 
    print_reverse_number(n, arr)
It still doesn't work. I still have the same mistake
Are you still receiving a runtime error? I wasn't receiving any errors when I ran this code. What exactly is the mistake you're running into?
Error:
Traceback (most recent call last): File "Solution.py", line 37, in <module> print_reverse_number(n, arr) File "Solution.py", line 11, in print_reverse_number n = int(input()) EOFError: EOF when reading a line
First of all - you are using nuke while you actually need a screwdriver.

Maybe I am hallucinating on Friday afternoon, but I if this is full description of your task:

Quote:Given an array, A, of N integers, print A's elements in reverse order as a single line of space-separated numbers.

then what you try to accomplish with your code? If there is no requirements what you haven't disclosed it should be as easy as:

>>> lst = list(range(1, 6))
>>> lst
[1, 2, 3, 4, 5]
>>> print(*reversed(lst), sep=' ')
5 4 3 2 1
Objective
Today, we're learning about the Array data structure. Check out the Tutorial tab for learning materials and an instructional video!

Task
Given an array,A , of N integers, print A 's elements in reverse order as a single line of space-separated numbers.

Input Format


The first line contains an integer,N (the size of our array).
The second line contains N space-separated integers describing array A's elements.

Constraints
1 <= N <= 1000

1<= Ai<=10000, where Ai is the ith integer in the array.
Output Format

Print the elements of array Ain reverse order as a single line of space-separated numbers.
Sample Input

4
1 4 3 2
Sample Output

2 3 4 1
I think this solution for this challenge, because I know only for and if conditions in Python and I see in documentation that there is a method call reverse () , but if there is another way I will accept and forgive me If I was wrong.