Back to General discussions forum
Python doesn't accept multiline input and the input that we're given contain test cases that are only separated by new line. When copied into a Python program, all those separate lines are changed into a single long line of different symbols. We can't separate them with spaces (for example with help of input() function) as there are also spaces in test cases themself. How do I copy and paste this input without altering it to have, for example, "\n" at the end of each line?
I think there are at least three options:
data = """example"""
.Thx. I quickly checked the option nr 3 and it worked, however I am a bit sad that for this solution I need to manualy paste the input field into my code (so the code can't accept data from another program for example). I guess in real life we wouldn't have this problem.
Do you use Python from the command line or do you use an IDE just as PyCharm?
To use stdin, you can do something like this:
n = int(input())
for i in range(n):
s = input()
...
I was using Sublime but this website expects you to use input(). Sublime doesn't have that functionality from the get go and I couldn't be bothered with watching 90 minutes tutorial on how to mod it so I came back to Jupyter notebook.
You do not have to use CodeAbbey to run your code. It's perfectly fine to run it locally as you see fit, and then copy & paste your result plus code over here.
Thanks to Mathias for quick help,
just I dare to add my two cents:
When copied into a Python program,
It is something which is strongly discouraged, normally computer programs shouldn't work with input data embedded into their source, right? :)
Sublime doesn't have that functionality from the get go
I'm not sure what you mean. Sublime is just a text editor as I remember, it is not Python. You normally have some Python
interpreter on your machine which you can run separately (in the command line), or probably use IDLE
environment,
if it is installed along with Python - or use some text editor (Sublime, VIM, Notepad++ etc). In the last case you
generally can edit your code in the editor but you should run it similarly to the 1st option, in the separate console
window or console built-in in the editor (if it is present). One of the most advanced editors of this kind is PyCharm,
but I don't remember well, it's probably not free.
Concluding, it is very important to learn how to run Python at all (rather than clicking some magic button in your editor). Regretfully this small site has no special exercise to help you learning "environment and infrastructure" but it is nevertheless very important.
PyCharm has a free Community Edition which is more than sufficient.
Suche IDEs handle calling python with the right parameters for you, but as Rodion wrote it's good to know the basics,
i.e. something like python3 ./python_program.py < ./data.txt
.
In this example, we call python3
to execute the program python_program.py
, and the contents of the file
data.txt
is presented as stdin to the program.