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 input & output parameters from command line argument shantanu97 1 696 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 950 Apr-04-2021, 06:10 PM
Last Post: Adrian_L
  Handling multi-input/output audio in python bor1904 4 1,058 Nov-04-2020, 08:25 AM
Last Post: CHLOVRL
  user input for multi-dimentional list without a prior iteration using input() Parshaw 6 951 Sep-22-2020, 04:46 PM
Last Post: Parshaw
  bad input line 3 how t fix it youssef210 2 796 Aug-27-2020, 04:57 PM
Last Post: nilamo
  Line charts error "'isnan' not supported for the input types," issac_n 1 903 Jul-22-2020, 04:34 PM
Last Post: issac_n
  Taking Multiple Command Line Argument Input bwdu 6 1,598 Mar-29-2020, 05:52 PM
Last Post: buran
  How to make input goto a different line mxl671 2 1,019 Feb-04-2020, 07:12 PM
Last Post: Marbelous
  Python convert multi line into single line formatted string karthidec 2 3,725 Dec-23-2019, 12:46 PM
Last Post: karthidec
  command line input (arg parse) and data exchange Simba 7 1,954 Dec-06-2019, 11:58 PM
Last Post: Simba

Forum Jump:

User Panel Messages

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