0

I'm trying to do an SPOJ problem and getting the number of test cases using:

tc = int(input())

However, I get a "non-zero exit code" error from that line when running my code. Here's the full code:

def is_on_edge(row, col, rows, cols):
    is_top = row == 0
    is_left = col == 0
    is_right = (col == cols - 1)
    is_bottom = (row == rows - 1)
    return is_top or is_left or is_right or is_bottom

tc = int(input())

for i in range(tc):
    rows, cols = map(int, input().split())
    for r in rows:
        for c in cols:
            if is_on_edge(r, c, rows, cols):
                print("*", end="")
            else:
                print(".", end="")
    print("")

Any idea what I'm doing incorrectly?

Thanks!

3
  • Why do you think the error has anything to do with that line? Commented Mar 22, 2017 at 19:53
  • @user2357112 Because the online judge gives me an end of file error from that line Commented Mar 22, 2017 at 19:54
  • You'll need to reproduce the error locally and see exactly what sort it is. Commented Mar 22, 2017 at 20:23

1 Answer 1

2
rows, cols = map(int, input().split())

makes rows and cols be ints

for r in rows:
    for c in cols:

tries to iterate ints, which raises an exception. After changing above to

for r in range(rows):
    for c in range(cols):

code runs without exception on Win10, 3.6.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.