Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Multi-line console input
#1
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
Reply
#2
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
Reply
#3
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
Reply
#4
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.
Reply
#5
(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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to add multi-line comment section? Winfried 1 139 Mar-24-2024, 04:34 PM
Last Post: deanhystad
  Receive Input on Same Line? johnywhy 8 609 Jan-16-2024, 03:45 AM
Last Post: johnywhy
  regex multi-line kucingkembar 6 1,444 Aug-27-2022, 10:27 PM
Last Post: kucingkembar
  multi-line CMD in one-line python kucingkembar 5 3,862 Jan-01-2022, 12:45 PM
Last Post: kucingkembar
  How to input & output parameters from command line argument shantanu97 1 2,507 Apr-13-2021, 02:12 PM
Last Post: Larz60+
  How to make input come after input if certain line inserted and if not runs OtherCode Adrian_L 6 3,271 Apr-04-2021, 06:10 PM
Last Post: Adrian_L
  Handling multi-input/output audio in python bor1904 4 3,496 Nov-04-2020, 08:25 AM
Last Post: CHLOVRL
  user input for multi-dimentional list without a prior iteration using input() Parshaw 6 2,688 Sep-22-2020, 04:46 PM
Last Post: Parshaw
  bad input line 3 how t fix it youssef210 2 2,655 Aug-27-2020, 04:57 PM
Last Post: nilamo
  Line charts error "'isnan' not supported for the input types," issac_n 1 2,368 Jul-22-2020, 04:34 PM
Last Post: issac_n

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020