Python Forum
Multi-line console input - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Multi-line console input (/thread-31651.html)



Multi-line console input - lizze - Dec-25-2020

Trying to read multi-line console input with my program. But as of know I need to press enter twice before the actual reading begins? Does anyone understand why? Am I using the input() function the wrong way?

Input data look like this:
Quote:...........*........
....*.....*.........
.........*..*...*...
*..*..*......***....
..*.....*...........
.*..................
.......*.........*.*
....................
.....*............*.

..........
.*.**.*...
*....*.*.*
..........
..*.....*.

def main():

    lines = []
    number_of_empty_lines = 0
    while True:
        line = input()
        if not line:
            number_of_empty_lines += 1
            if number_of_empty_lines == 2:
                break
        else:
            number_of_empty_lines = 0
            pass

        lines.append(line)

    numberOfStars = 0
    for i in lines:
        if i == "":
            print()
            numberOfStars = 0
            continue

        starCounter = i.count("*")
        print("." * (len(i) - starCounter- numberOfStars), end="")
        print("*" * starCounter, end="")
        print("." * numberOfStars)
        numberOfStars += starCounter



RE: Multi-line console input - DPaul - Dec-25-2020

Hi,

It's not clear to me what you are trying to achieve here.
What is input and what is supposed to happen.

One thing, : you have a def main(),
but you are not calling it.

Paul


RE: Multi-line console input - lizze - Dec-25-2020

Hi, the program should take that input posted above and fix the fragmentation.

Output should look like this:
Quote:...................*
.................**.
..............***...
........******......
......**............
.....*..............
..***...............
....................
**..................

..........
......****
..****....
..........
**........

The program works and I´m getting the right output. However, I need to press 'enter' on the keyboard twice after pasting input. That´s the problem!

I´m calling the main function, did just not put in the description here


RE: Multi-line console input - bowlofred - Dec-25-2020

The program appears to be waiting for 2 empty lines. You probably only have one empty line at the end when you paste it. When you hit return, it makes a second empty line.

Or, your console strips the final newline and you have to hit return to add it back. Either is possible.


RE: Multi-line console input - lizze - Dec-26-2020

(Dec-25-2020, 06:28 PM)DPaul Wrote: Hi,

It's not clear to me what you are trying to achieve here.
What is input and what is supposed to happen.

One thing, : you have a def main(),
but you are not calling it.

Paul

(Dec-25-2020, 10:31 PM)bowlofred Wrote: The program appears to be waiting for 2 empty lines. You probably only have one empty line at the end when you paste it. When you hit return, it makes a second empty line.

Or, your console strips the final newline and you have to hit return to add it back. Either is possible.

Yes that exactly what happens. Any suggestion how I can do instead?
I need to break the loop after all input has been stored in lines[]. How can I do that without putting me in this 'enter' trap