1

I am trying to get the user to input a string, I then want to count the number of lines they have inputted and save it in a variable to use in a for loop. so far I have tried this:

asciiart = input("Please enter your entire ASCII art: ")
nlines = len(asciiart.split('\n'))
print(nlines)
John Coleman
  • 51,337
  • 7
  • 54
  • 119
fvw
  • 11
  • 1
  • 2
    The problem is that the first enter terminates the `input`. You need to use a loop, together with some way for the user to indicate when input is finished. – John Coleman Nov 14 '19 at 18:08
  • The combination of the two questions linked here should help you out @fvw. Let us know if that's not sufficient – Brad Solomon Nov 14 '19 at 18:15
  • The solution to the multiline problem involving `sys.stdin.read()` is probably best in the sense that for ascii art you run the risk of interference if you use a special string as an end-of-input sentinel. How do you know the sentinel wasn't part of the art? On the other hand, you can doubtless come up with a sentinel which is unlikely to be used in any art, and just live with the potential ambiguity. – John Coleman Nov 14 '19 at 18:23

0 Answers0