1 / 9
Mar 2011

how the heck am i getting wrong answer on bishops??
i'm pretty sure the answer is 2*n -2, except for 1 where it's 1.

How the ... do you think can anyone know without having a look at your code??

import sys
while True:
    try:
        value = io.readline()
    except:
        break
    value = int(value)
    if value == 1:
        print(1)
    else:
       value = 2*value -2
       print(value)

Be careful with unspecified "except"-clauses. Stupid mistake! Try this:

[bbone=Python,122]import sys
while True:
try:
value = io.readline()
except EOFError:
break
value = int(value)
if value == 1:
print(1)
else:
value = 2*value -2
print(value)[/bbone]

3 months later

def bishop(n):
    return(2*n-2)
while 1:
    try:
        r=int(raw_input())
    except EOFError:
        break
    print(bishop(r))

i am getting wrong answer why?

4 months later

Help needed
How to run bishop code when test cases are in files?

n=raw_input()
n=int(n)
sum=2*n-2
if n==1:
sum=1
print sum

What kind of files?
Input is read via stdin, output via stdin.

According to your code:
If you show Python code you must have a look at the indentation.

8 years later

If you are getting WA(using strings in c++), check for corner cases:
N = 0, 1, 5, 50, 500, 5000…so on
Required output for these cases is 0, 1, 8, 98, 998, 9998,…so on respectively.
And not : 8, 0, 08, 098, 0998, 09998…so on respectively.