datacamp-light icon indicating copy to clipboard operation
datacamp-light copied to clipboard

input() function is not working

Open HiraMariam opened this issue 5 years ago • 2 comments

I have added the input() function but it shows error in the shell Capture

https://python-tricks.com/control-statements-in-python/

HiraMariam avatar Jul 22 '19 12:07 HiraMariam

I encountered the same issue and made a workaround:

<code data-type="pre-exercise-code">
    import sys
    from io import StringIO
    sys.stdin = StringIO("input\n")
    del sys
</code>

Now the standart input has the string "input" hardcoded inside; it's not great, but it works. You can write it in the pre-exercise-code section, if you are configuratin' the exercise; or at the beginning of your python code, if you don't have the acess to the file itself.

thlmenezes avatar Oct 27 '19 19:10 thlmenezes

anyone got it working?

WeatherAnchor avatar Oct 19 '20 08:10 WeatherAnchor