Kartikeya Singh
Kartikeya Singh

Reputation: 13

Why am I getting RE for this code on Google Code Jam?

I wrote the following code and tried to submit it. It works perfectly on my own machine but when I try to test run it on their website, it says there was a runtime error. This is not the first question where I have encountered this but the second. This is not a logical error but something wrong with the syntax or how I am taking the inputs maybe. Please tell me what I'm doing wrong. Thanks in advance.

Screenshot of code with problem statement from the website

Here's the code if you couldn't see the picture:

t = int(input().strip())
for i in range(1, t+1):
    n = int(input().strip())
    p = input().strip()
    res = ""
    for c in p:
        if c == 'E':
            res += 'S'
        else:
            res += 'E'
    print(f"Case #{i}: {res}")

Upvotes: 1

Views: 192

Answers (1)

Gagandeep Kalra
Gagandeep Kalra

Reputation: 1055

t = int(input().strip())
for i in range(1, t+1):
    n = int(input().strip())
    p = input().strip()
    res = ""
    for c in p:
        if c == 'E':
            res += 'S'
        else:
            res += 'E'
    print("Case #{}: {}".format(i, res))

I'm guessing whatever version google runs is less than 3.6 when f-strings were introduced; verified this works.

Upvotes: 1

Related Questions