NZEC error while running solution to problem :Rise and Fall of Power

Hello,

I am encountering an NZEC error whenever I submit my python solution to the problem : The Rise and Fall of power.

I have tested the code to be running successfully on my terminal prior to uploading it to CodeChef.

Here is my python code:

    Last login: Sun Jul 21 08:38:18 on console
prahalad-deshpandes-macbook-air:~ prahaladdeshpande$ cd python
prahalad-deshpandes-macbook-air:python prahaladdeshpande$ vim number_extractor.py 
prahalad-deshpandes-macbook-air:python prahaladdeshpande$ vim number_extractor.py 
prahalad-deshpandes-macbook-air:python prahaladdeshpande$ ls
hello.py		src			variablescope.pyc
hello.txt		testjEdit.py		variablescopeuser.py
iprange_generator.py	untitled folder
number_extractor.py	variablescope.py
prahalad-deshpandes-macbook-air:python prahaladdeshpande$ cat hello.txt  | python number_extractor.py 
25 56
387 489
prahalad-deshpandes-macbook-air:python prahaladdeshpande$ vim number_extractor.py 
prahalad-deshpandes-macbook-air:python prahaladdeshpande$ cp number_extractor.py number_extractor_debug.py
prahalad-deshpandes-macbook-air:python prahaladdeshpande$ vim number_extractor_debug.py 
prahalad-deshpandes-macbook-air:python prahaladdeshpande$ cat hello.txt | python number_extractor_debug.py 
  File "number_extractor_debug.py", line 16
    T = int(sys.stdin.read()))
                             ^
SyntaxError: invalid syntax
prahalad-deshpandes-macbook-air:python prahaladdeshpande$ vim number_extractor_debug.py 
prahalad-deshpandes-macbook-air:python prahaladdeshpande$ cat hello.txt | python number_extractor_debug.py 
Traceback (most recent call last):
  File "number_extractor_debug.py", line 16, in 
    T = int(sys.stdin.read())
ValueError: invalid literal for int() with base 10: '2\n4 2\n9 3\n'
prahalad-deshpandes-macbook-air:python prahaladdeshpande$ vim number_extractor_debug.py 
prahalad-deshpandes-macbook-air:python prahaladdeshpande$ cat hello.txt | python number_extractor_debug.py 
Traceback (most recent call last):
  File "number_extractor_debug.py", line 20, in 
    input_testcase = (sys.stdin.read().splitlines())[0].split()
IndexError: list index out of range
prahalad-deshpandes-macbook-air:python prahaladdeshpande$ vim number_extractor_debug.py 
prahalad-deshpandes-macbook-air:python prahaladdeshpande$ cat hello.txt | python number_extractor_debug.py 
Testcase number 2
import sys
import os
import math

def extract(k,n):
        x = math.floor(math.pow(k,k))

        log10x = int(math.ceil(math.log10(x)))

        left_most_digits = math.floor(x/(math.pow(10, log10x-n)))
        right_most_digits = math.floor(x%(math.pow(10,n)))
        print str(int(left_most_digits)) +" " + str(int(right_most_digits))

if __name__ == "__main__":

        T = int(sys.stdin.next())
        num_pair_list = []

        try:
                for i in xrange(T):
                        k,v =  map(int, sys.stdin.next().split())
                        extract(k,v)
        except StopIteration as  si:
                pass

Can anyone tell me what’s going wrong here ? Why does this problem not run on Codechef, however executes on my local machine.

By the way, I run the script as follows on my local machine:

cat testfile.txt | python number_extractor.py

testfile.txt - contains the test cases.
number_extractor.py - contains the above python logic

1 Like