Python Forum

Full Version: Multi-line console input
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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
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
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
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.
(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