I would like to include both input and output cells that look like Jupyter IPython cells. The "IPython Notebook cells with listings" at IPython Notebook cells with listings shows how to do a single input cell but I would like to display several lines with both input and output lines, something like this, for example, where Out[ ] does not advance the counter but In[ ] does:

1 Answer
1

I also started with the link you provided and came up with this solution. Basically you define three listing environments (one for inputs, one for printed text, and one for output). I admit that the solution is not super-elegant (repeated definition of options) but it works well offering you automatic numbering and even supporting labeling/referencing.