Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Unable to execute input().
#1
Unable to run the below code.

# your code goes here
def get_input():
    my_var = str(input('Enter "a" or "b": '))
    if my_var == "a" or my_var == "b":
        print('got input:', my_var)
        return my_var
    else:
        print('You didn\'t type "a" or "b". Try again.')
        return get_input()


def get_input1():
    my_var = input('Enter "a" or "b": ')

    if my_var != "a" and my_var != "b":
        print('You didn\'t type "a" or "b". Try again.')
        return get_input1()
    else:
        return my_var

print('got input:', get_input1())

#get_input()
Get error:

Traceback (most recent call last):
File "prog.py", line 21, in <module>
File "prog.py", line 13, in get_input1
EOFError: EOF when reading a line
Reply
#2
(Feb-17-2021, 07:01 AM)jahuja73 Wrote: Unable to run the below code.

# your code goes here
def get_input():
    my_var = str(input('Enter "a" or "b": '))
    if my_var == "a" or my_var == "b":
        print('got input:', my_var)
        return my_var
    else:
        print('You didn\'t type "a" or "b". Try again.')
        return get_input()


def get_input1():
    my_var = input('Enter "a" or "b": ')

    if my_var != "a" and my_var != "b":
        print('You didn\'t type "a" or "b". Try again.')
        return get_input1()
    else:
        return my_var

print('got input:', get_input1())

#get_input()
Get error:

Traceback (most recent call last):
File "prog.py", line 21, in <module>
File "prog.py", line 13, in get_input1
EOFError: EOF when reading a line

I don't get any errors when running that code. Neither when running it as is or when changing it to use the function "get_input()". Not perfect, but it runs without errors.
Reply
#3
(Feb-17-2021, 07:53 AM)Serafim Wrote: I don't get any errors when running that code. Neither when running it as is or when changing it to use the function "get_input()". Not perfect, but it runs without errors.
I tried online at :
https://ideone.com/EulG3N

Please tell if it is a site (platform) based error on execution.
Reply
#4
You'll get that EOFError: EOF when reading a line error if input() gets an "end-of-file" condition. Perhaps by being redirected to an empty/unreadable file, terminated with a control-D/control-Z, or problems connecting to the correct input device.

Output:
$ python -c 'input("type input:")' type input:k
But when redirected so that no data can be read:

Output:
$ python -c 'input("type input:")' < /dev/null type input:Traceback (most recent call last): File "<string>", line 1, in <module> EOFError: EOF when reading a line
Reply
#5
(Feb-17-2021, 08:51 AM)bowlofred Wrote: You'll get that EOFError: EOF when reading a line error if input() gets an "end-of-file" condition. Perhaps by being redirected to an empty/unreadable file, terminated with a control-D/control-Z, or problems connecting to the correct input device.

Output:
$ python -c 'input("type input:")' type input:k
But when redirected so that no data can be read:

Output:
$ python -c 'input("type input:")' < /dev/null type input:Traceback (most recent call last): File "<string>", line 1, in <module> EOFError: EOF when reading a line

But, request a way to remove the error on ideone.com, as usually run there only.

It would help in future too for taking an input.
Reply
#6
Looks like you can't do interactive stuff on ideone. But you can type in the input ahead of time.

Below your code should be another window with the "input" tab. Type in your answers there and it will feed it to the program when you run.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Unable to access the user input value given to daterangepicker klllmmm 1 2,267 May-26-2021, 09:16 PM
Last Post: nilamo
  Possible to execute a python script before log off/shutdown with input commands? Kaltex 1 2,232 May-18-2021, 06:31 AM
Last Post: Skaperen
  Unable to understand how given code takes a fixed input value, without inputting. jahuja73 4 2,645 Jan-28-2021, 05:22 PM
Last Post: snippsat
  How to write a script to execute a program need passing additional input? larkypython 2 2,467 Nov-23-2019, 04:38 AM
Last Post: larkypython
  Unable to execute the for loop harold 1 1,699 Sep-23-2019, 12:27 PM
Last Post: buran
  unable to pass a input after changing the user from root to non root using python avinash 3 3,124 Apr-08-2019, 10:05 AM
Last Post: avinash
  Unable to use sqlanydb to execute Sybase IQ Stored Procedure FORTITUDE 4 3,734 Sep-15-2018, 05:03 PM
Last Post: FORTITUDE
  How do I accept input from the terminal when I execute my file? cocoa1231 1 4,078 Dec-08-2016, 11:22 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

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