Runtime Error (NZEC) - Python / Codechef - python

I'm getting started with Codechef. I submitted following code in python to solve this question.
The code below works fine with codechef's online (python) IDE as well as my local IDE. But, when I submit it on codechef, it results in Runtime Error (NZEC). Can someone explain to me the reason behind this?
withdrawCash = int(input())
totalCash = int(input())
if withdrawCash < totalCash and withdrawCash % 5 is 0:
totalCash = (totalCash - withdrawCash) - 0.5
print(totalCash)

The problem supplies both the inputs in a single line. Your code waits for input in 2 lines. Change it to:
withdrawCash,totalCash = map(int,raw_input.split())

NZEC (Non Zero Exit Code) occurs when your code doesn't return zero on exit. It can happen due to a number of reasons, but if splitting the input doesn't solve the problem, add an exception for EOFerror. Just write:
try:
withdrawCash = int(input().split()) # raw_input in the case of Python 2
except EOFerror:
print ("exit") # this is jst a pseudo statement `
Use indentation properly. I am currently using an android app of stack exchange in which writing code is not so easy. codechef is pretty poor when it comes to Python. Switch to any other lang for CP.

Try directly submitting the code without running it on Codechef ide because it with me also it showed the same but when I submitted directly I got submitted successfully. so Directly submit your code.

Related

bingads V13 report request fails in python sdk

I try to download a bingads report using python SDK, but I keep getting an error says: "Type not found: 'Aggregation'" after submitting a report request. I've tried all 4 options mentioned in the following link:
https://github.com/BingAds/BingAds-Python-SDK/blob/master/examples/v13/report_requests.py
Authentication process prior to request works just fine.
I execute the following:
report_request = get_report_request(authorization_data.account_id)
reporting_download_parameters = ReportingDownloadParameters(
report_request=report_request,
result_file_directory=FILE_DIRECTORY,
result_file_name=RESULT_FILE_NAME,
overwrite_result_file=True, # Set this value true if you want to overwrite the same file.
timeout_in_milliseconds=TIMEOUT_IN_MILLISECONDS
)
output_status_message("-----\nAwaiting download_report...")
download_report(reporting_download_parameters)
after a careful debugging, it seems that the program fails when trying to execute a command within "reporting_service_manager.py". Here is workflow:
download_report(self, download_parameters):
report_file_path = self.download_file(download_parameters)
then:
download_file(self, download_parameters):
operation = self.submit_download(download_parameters.report_request)
then:
submit_download(self, report_request):
self.normalize_request(report_request)
response = self.service_client.SubmitGenerateReport(report_request)
SubmitGenerateReport starts a sequence of events ending with a call to "_SeviceCall.init" function within "service_client.py", returning an exception "Type not found: 'Aggregation'"
try:
response = self.service_client.soap_client.service.__getattr__(self.name)(*args, **kwargs)
return response
except Exception as ex:
if need_to_refresh_token is False \
and self.service_client.refresh_oauth_tokens_automatically \
and self.service_client._is_expired_token_exception(ex):
need_to_refresh_token = True
else:
raise ex
Can anyone shed some light? .
Thanks
Please be sure to set Aggregation e.g., as shown here.
aggregation = 'Daily'
If the report type does not use aggregation, you can set Aggregation=None.
Does this help?
This may be a bit late 2 months after the fact but maybe this will help someone else. I had the same error (though I suppose it may not be the same issue). It does look like you did what I did (and I'm sure others will as well): copy-paste the Microsoft example code and tried to run it only to find that it didn't work.
I spent quite some time trying to debug the issue and it looked to me like the XML wasn't being searched correctly. I was using suds-py3 for the script at the time so I tried suds-community and everything just worked after that.
I also re-read the Bing Ads API walkthrough for getting started again and found that they recommend suds-jurko instead.
Long story short: If you want to use the bingads API don't use suds-py3, use either suds-community (which I can confirm works for everything I've used the API for) or suds-jurko (which is the one recommended by Microsoft).

How to get rid of run time error on code chef

The following code works fine on both the jupiter notebook and the pycharm but its showing runtime error on codechef. The code is to check whether the permutation is ambiguous or not.
for i in range(int(input())):
n=int(input())
l=list(map(int,input().split()))
p=l[:]
for j in range(n):
p[l[j]-1]=j+1
if(p==l):
print("ambiguous")
else:
print("not ambiguous")
Welcome to Stack Overflow!
When posting, it usually helps to add more information, such as the error message itself. Regardless, I pasted your code into Python and I've deduced that the problem arises from the input() statement- I'm not sure what 'code chef' is, but it probably doesn't know that the user should input an integer into the input() prompt.
Therefore, a workaround is to hardcode your inputs as variables:
input1 = "5"
input2 = ...
for i in range(int(input1)):
n=int(input2)
...

my python functions do not work in jupyter notebook

i have written lines of code that run normally in jupyter notebook (here is the code below):
umd_departments = requests.get("https://api.umd.io/v0/courses/departments")
umd_departments_list = umd_departments.json()
umd_departments_list2 = json.dumps(umd_departments_list, indent=1)
department_storage = [department['dept_id'] for department in umd_departments_list]
print(department_storage)
the code above usually gives me the output i want and prints it out immediately. the issue i run into is when i try and put the code above into a function of its own it doesn't work
def get_UMD_departments():
umd_departments = requests.get("https://api.umd.io/v0/courses/departments")
umd_departments_list = umd_departments.json()
umd_departments_list2 = json.dumps(umd_departments_list, indent=1)
department_storage = [department['dept_id'] for department in umd_departments_list]
print(department_storage)
the problem i face with this version of code is that it never prints out anything as oppose to the other code i showed. with this code, i also don't get an error when i run it since the * symbol doesn't show up and i don't get an error message. so i'm not sure what the problem is. it usually just shows how many times i ran the cell. i was wondering if anyone knew a way to make the function version of my code to work, greatly appreciated.

Runtime Error for 'COOMILK' on CodeChef (Python 3.4)

Hi I am new to Python programming as well as here. I am practicing on www.codechef.com but I am not able to find the solution for the error on my code.
I am using Python 3.4, I am trying to solve this problem https://www.codechef.com/problems/COOMILK
While my code is running perfectly on IDLE it is giving a runtime error when I am trying to submit my code. I tried all the searches and first fixed the EOFerror which I was getting on compilation but now I am not able to fix this Runtime error.
T = int(input())
for loop in range(T):
failed = False
N = int(input())
activities = input().split()
for check in range(N):
if len(activities)==1 and activities[check]== 'cookie':
print ("NO")
failed = True
elif activities[check] == 'cookie' and activities[check+1]!= 'milk':
print ("NO")
failed = True
if not failed:
print("YES")
It would be great if someone help me out in finding out the problem, I have already checked the code with providing the input as required and it is giving desired output but somehow is giving runtime error on submission.
I will appreciate suggestions on improving my code.
Thank you :)

Not allowing numbers in Glade with Python

I'm a fairly new Python programmer (started 3 days ago). I'm working as a apprentice for a civil engineer and he asked me to do some simpler tasks for his program, as of the objective I should work with is to not allow numbers from inputs in certain glade objects.
The code I've been struggling with creating is as such:
def testOmHeltal (self, number1):
textviewResultat = self.builder.get_object("textviewResultat")
text = gtk.TextBuffer()
try:
#print number1.get_text()
#temp = number1.get_text() + number1.get_text()
temp = float(number1.get_text())
except ValueError:
text.set_text("ERROR: Endast Nummer")
self.builder.get_object("hboxWarning").show()
self.builder.get_object("image12").show()
self.builder.get_object("textviewResultat").set_buffer(text)
return 0
self.builder.get_object("hboxWarning").hide()
self.builder.get_object("image12").hide()
def quit(self, widget):
sys.exit(0)
This code is called upon at the location of the glade object with this line:
self.testOmHeltal(entryGladeObject)
Now to the problem at hand, I allways get an Float error as such:
File "bvf.py", line 393, in utfora
+float(entryTjockleksskyddslager.get_text<>>>>
ValueError: invalid literal for float<>: 0.04e
0.04e is the invalid input and line 393 is a piece of my Chiefs code, since all he uses is float all the time and I shouldn't meddle with it too much I'm kind of panicking alittle..
I understand that float can only start and end with a number to not give an error, but since my "code" bit wants an error(or rather, an exception) to start the 'hboxWarning' and 'image12' of someone using a letter instead of the supposed number, I'm at a loss at what to do ><
Instead of showing my error with hboxWarning and image12, nothing happens at all...
Any hints or advice would help alot.
I don't know if I understood correctly, but the error is not on your code, right?
All I can assume is that there's a piece of code trying to convert the value to float before your verification. If that's the case, you should verify the value before any processing is done on it, or move the try-except code around the faulty code, depending on the processing itself (for example, if the processing implies database manipulation, it would be safer to do all the verifications previously).
If the error is happening before the line where you run self.testOmHeltal(entryGladeObject), the execution of the signal/method stops right away and your code is never excecuted; that's why the warning isn't showing.

Categories

Resources