Python Forum
EOFError: EOF when reading a line - Runtime Error
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
EOFError: EOF when reading a line - Runtime Error
#1
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
Reply
#2
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)
Reply
#3
It still doesn't work. I still have the same mistake
Reply
#4
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?
Reply
#5
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
Reply
#6
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
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Reply
#7
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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  class and runtime akbarza 4 282 Mar-16-2024, 01:32 PM
Last Post: deanhystad
  Reading and storing a line of output from pexpect child eagerissac 1 4,148 Feb-20-2024, 05:51 AM
Last Post: ayoshittu
  Reading in of line not working? garynewport 2 786 Sep-19-2023, 02:22 PM
Last Post: snippsat
  xlwings error when reading a workbook Mishal0488 1 1,043 Aug-01-2023, 02:05 AM
Last Post: deanhystad
  File "<string>", line 19, in <module> error is related to what? Frankduc 9 12,393 Mar-09-2023, 07:22 AM
Last Post: LocklearSusan
  painfully slow runtime when handling data dadazhu 3 910 Jan-20-2023, 07:11 PM
Last Post: snippsat
  Big O runtime nested for loop and append yarinsh 4 1,332 Dec-31-2022, 11:50 PM
Last Post: stevendaprano
  Pandas - error when running Pycharm, but works on cmd line zxcv101 1 1,321 Jun-18-2022, 01:09 PM
Last Post: snippsat
  I have an issue with Netmiko Error reading SSH protocol banner omarhegazy 2 3,513 May-16-2022, 06:05 PM
Last Post: omarhegazy
  Reducing runtime memory usage in Cpython interpreter david_the_graower 2 2,175 Oct-18-2021, 09:56 PM
Last Post: david_the_graower

Forum Jump:

User Panel Messages

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