1

I'm trying to make a pattern in HackerRank and as far as I can tell, my solution works.

size = int(input())
letters = 'abcdefghijklmnopqrstuvwxyz'
for i in range(size):
    textp = "-".join(letters[size - 1: size - (1 + i): -1])
    textn = "-".join(letters[size - i: size: 1])
    print(textp.rjust(size + 2, '-') + '-' + letters[size - (1 + i)] + '-' + textn.ljust(size + 2, '-'))
for i in range(size - 2, -1, -1):
    textp = "-".join(letters[size - 1: size - (1 + i): -1])
    textn = "-".join(letters[size - i: size: 1])
    print(textp.rjust(size + 2, '-') + '-' + letters[size - (1 + i)] + '-' + textn.ljust(size + 2, '-')) 

prints out:

--------e--------
------e-d-e------
----e-d-c-d-e----
--e-d-c-b-c-d-e--
e-d-c-b-a-b-c-d-e
--e-d-c-b-c-d-e--
----e-d-c-d-e----
------e-d-e------
--------e--------

But when I try to submit it I get

File "solution.py", line 12, in <module>
n = int(input())
EOFError: EOF when reading a line

I'm new to python so I'm not sure how to resolve this error. The code works fine and I don't understand why the input() function is messing up.

  • What do you submit exactly? – Xantium Mar 18 '18 at 01:45
  • this error is saying you're trying to read for an input this assignment doesn't provide. I.e., you have too many `input()`s in the code. Also, this line is not even in the question code: `n = int(input())` – Marat Mar 18 '18 at 01:52
  • Possibly relevant: https://stackoverflow.com/questions/17675925/eoferror-eof-when-reading-a-line – dROOOze Mar 18 '18 at 01:55
  • @Simon as input I type in a number that decides how wide the diamond pattern will be. Its a single integer on a single line. So for the example above I typed in 5, therefore the pattern was 5 letters wide. –  Mar 18 '18 at 15:42
  • @Marat yea I realize that I never even typed that line which is why I'm even more confused. And I only have one input line which is where I type the single number that decides the size of the pattern, so I'm not sure why too many inputs would be the problem –  Mar 18 '18 at 15:46

1 Answers1

1

OK so i figured it out. There was a little tab at the bottom of the interpreter that had this code:

if __name__ == '__main__':
   n = int(input())
   print_rangoli(n)

I had to remove the size = int(input()) and I had to enclose the code in a function called print_ragnoli(s)