Runtime error in codechef - python

I am not here to ask any solution. Please keep in mind. I am tring to solve a problem April challange. My solution gives correct output when i run it using python over my computer but it gives runtime error when i submit the code. I dont want to give the whole code as its ongoing contest.
I am sure i have taken care of all the boundary conditions.
Here is what i am trying to do. Simply i am traversing the array and doing some operations as given in the problem.
problem link(if u want to see ranges of integers used)
http://www.codechef.com/APRIL14/problems/ADIGIT
n,t=map(int,raw_input().split())
a=raw_input()
a=[int(s) for s in a]
while(t):
//do something
t=t-1

Most of the time runtime error occurs when you try to access the invalid memory or declare a huge bunch of memory.

Related

(gnuradio) Is there a way I can use "python block" to make a source?

I have an ADC module with 1 MHZ sampling rate.
Here is the URL of his sample program
I will give him a 40khz carrier signal as an analog input. I want to write the voltage signal he received into the "python block" of "GNURADIO". let his
output_items[0][:]=adc.readA1Volts()
But when I do this it runs out:
swig director method error: error detected when calling 'feval_p.eval'
Is there any way I can achieve this?
(I'm not very good in English, I translated it by Google, sorry)
Generally, yes. You can write a GNU Radio source in Python.
output_items[0][:]=adc.readA1Volts()
That says "assign the many items in output_items[0] the value or values from adc.readA1Volts(), which is almost certainly not correct.
Possibly, something throws an error here, maybe because of array size mismatch or similar, and hence that error you see arises.
I think this reflects a bit of misunderstanding on how to write a python block. The Official GNU Radio Tutorials might be the best place to start.
adc.readA1Volts() is a single voltage (POINT) that will read adc, I can store it as a matrix,
ex:
ADC=[]
ADC.append(adc.readA1Volts())
Then it is output by output_items[0],
ex:
output_items[0][:]=ADC
Is this thought correct?
I don't know what his output form is like.

Returning detailed messages for compilation errors in Python

I recently received a grade of 0 for an assessment piece due to the marker using an older version of Python and receiving a syntax error in a match case loop causing it to fail to start (though that's been sorted and reassessed correctly now). So now I want to implement a fail-safe in case it happens again (as there is a second part of the same assessment).
Currently I am using a try except block around my match case loop to check for a syntax error. However this does not trigger like I thought it would, I'm assuming because it's a compilation error rather than a runtime error. So obviously it wasn't going to work. My next solution was to add a check for which version of Python is running but now that I know its a compilation error that won't work either.
So my question is: is there a way to show more detailed messages from errors generated during compilation of my code? The error message returned by default isn't very descriptive of the issue (for instance, that the incorrect version of Python is being used). I have added a comment to my code but I want to minimize the chances I'll have to appeal my grade again.

How can I fix "[mccabe] Cyclomatic complexity too high: 15 (threshold 15)" warning?

I am new to Python, my first programming language 2 days ago. I got the error "[mccabe] Cyclomatic complexity too high: 15 (threshold 15)" and I tried to fix it. If you could explain it and give me a command to solve it, I'd appreciate it.
Otherwise, I have an idea to solve this problem. I want to append a block to a block at the original command line to solve that problem. The problem is I don't know its code and does it work? (I have marked # on the link I shared). Once again I appreciate it and thank you very much.
It is not an error, merely a warning. Some editors/linters checks for code complexity as complex code is hard to maintain. You just got a warning that your code seems to be too complex based on certain rules. You can safely ignore it (in the sense that your code will run normally as these checks are not done during runtime).
However, if you get such warning, I recommend to take a look on the function and think if it would make sense to rewrite the code (and potentially split it into several functions).
It is also possible to disable such warnings (depending on the linter/editor you are using). For example, look here . (I would advise against disabling the warning globally as too complex code is not a good code style)
Take a look at this answer and this article if you are interested in more details.

Edit and run a sequence of scripts in a less-manual way [Python]

I am trying to find a way to edit and run a sequence of python scripts in a less manual way.
For context, I am running a series of simulations, which consist in running three codes in order 10 times, making minor changes to each code every time. The problem I am encountering is that this process leads to easy mistakes and chaotic work.
These are the type of edits I have to make to each code.
- Modify input/output file name
- Change value of a parameter
What is the best practice to deal with this? I imagine that the best idea would be to write another python script that does all this. Is there a way to edit other python codes, from within a code, and run them?
I don't intend or want anyone to write a code for me. I just need to be pointed in a general direction. I have searched for ways to 'automatize' codes, but haven't yet been successful in finding a solution to my query (mainly the editing part).
Thanks!
The thing that can change (files or parameter values) should be able to be either passed in or injected. Could be from a command line parameter, configuration file, or method argument. This is the "general direction" I offer.

Knowing exactly where which computation process wrong in intellij

I have the following python code inside a large loop
arr_a[indx]*arr_b[arr_c[indx],]
and with one running, an exception occurred and it said index out of range, but there are two possibilities(indx is out of range for predictErr, or arr_c[indx]), how do I know which part goes wrong?
This problem also extend to some general case that when one write several operations in one line and when things goes wrong, it is hard to tell which part causes this, and note that the above mentioned expression is inside a large loop, which means one can not simply start a debug mode and find that out.
Add a print statement for each segment that might be to blame to see which one fails:
print arr_a[indx]
print arr_c[indx]
arr_a[indx]*arr_b[arr_c[indx],]

Categories