Getting NZEC Error while submitting solution in codechef - python-3.x

This is my code for a particular question on codechef :
n=int(input())
for _ in range(n):
a,b =input().split()
a=int(a)
b=int(b)
x=[int(q) for q in input().split()]
x.sort(reverse=True)
new_x=[item for pos,item in enumerate(x) if x.index(item)==pos]
last=new_x[b]
i=x.index(last)
ans= i - 1 + x.count(last)
print(ans)
It passes all the test cases when I try it on my own environment but shows runtime (NZEC) when I submit the solution.
I searched a lot on internet but not able to figure out the problem.
Please help me out.

Related

np.isnan() function not solving "divide by zero encountered in true_divide" warning

Pdict = {"KobeBryant":0,"JoeJohnson":1,"LeBronJames":2,"CarmeloAnthony":3,"DwightHoward":4,"ChrisBosh":5,"ChrisPaul":6,"KevinDurant":7,"DerrickRose":8,"DwayneWade":9}
Salary = np.array([KobeBryant_Salary, JoeJohnson_Salary, LeBronJames_Salary, CarmeloAnthony_Salary, DwightHoward_Salary, ChrisBosh_Salary, ChrisPaul_Salary, KevinDurant_Salary, DerrickRose_Salary, DwayneWade_Salary])
Games = np.array([KobeBryant_G, JoeJohnson_G, LeBronJames_G, CarmeloAnthony_G, DwightHoward_G, ChrisBosh_G, ChrisPaul_G, KevinDurant_G, DerrickRose_G, DwayneWade_G])
plr =[]
for v in Pdict.values():
for s in Salary:
for g in Games:
if np.isnan(g[v]) == True: continue
z = np.round(np.divide(s[v], Games[v]), 2)
plr.append(z)
print(plr)
print(type(z))
Im trying to make a new matrix called plr, there is a zero in Games[] and Im trying to make it skip it instead of giving me that error. I found the np.isnan() but it seems to do nothing here. If I run the code with or without that line, it still gives me the runtime warning. Im not sure what Im doing wrong with it or is there a better way to do this?

module 'tensorboard.summary._tf.summary' has no attribute 'import_event'

I'm playing around a code from a book, however, there is an error that I can't manage to solve. This is my code:
from tensorboard.plugins.hparams import api_pb2
from tensorboard.plugins.hparams import summary as hparams_summary
def run_experiment(run_dir, hparams):
writer = tf.summary.create_file_writer(run_dir)
summary_start = hparams_summary.session_start_pb(hparams=hparams)
with writer.as_default():
accuracy = train_test_hp(hparams)
summary_end = hparams_summary.session_end_pb(api_pb2.STATUS_SUCCESS)
tf.summary.scalar('accuracy',accuracy,step=1,description="The accuracy")
tf.summary.import_event(tf.compat.v1.Event(summary=summary_start).SerializeToString())
tf.summary.import_event(tf.compat.v1.Event(summary=summary_end).SerializeToString())
return accuracy
This is the error I got:
module 'tensorboard.summary._tf.summary' has no attribute
'import_event'
I'm using colab. Please give me ideas about resolving the error. Your help means a lot to me!
Changing lines:
tf.summary.import_event(tf.compat.v1.Event(summary=summary_start).SerializeToString())
tf.summary.import_event(tf.compat.v1.Event(summary=summary_end).SerializeToString())
to:
tf.compat.v1.summary.Event(summary=summary_start).SerializeToString()
tf.compat.v1.summary.Event(summary=summary_end).SerializeToString()
solves the problem.

Why does my code stuck after speak function?

I try to create a Voice Assistant on python3
This is my function Speak (with pyttsx):
def speak(what):
print("Gosha: " + what)
speak_engine.say( what )
speak_engine.runAndWait()
speak_engine.stop()
in the main body it works fine, but in function execute_cmd, after Speak function my code stucks.
One part of execute_cmd:
def execute_cmd(cmd, voice):
global finished
finished = False
#import debug
if cmd == 'ctime':
now = datetime.datetime.now()
hours = str(now.hour)
minutes = str(now.minute)
if (now.minute < 10): minutes = '0' + minutes
speak("Now " + hours + ":" + minutes)
finished = True
finished will never True
This happens anywhere in the function
pls help me
(sorry for my eng, I'm from Russia)
UPD: I debugged my code and noticed, my code get stuck on speak_engine.runAndWait()
I know, many people have same problem, but their solutions didn't help me
I'm not sure I understand you problem. What exactly do you mean by your code getting "Stuck"? Since you said that your finished variable will never be False, I assume that the code runs through and doesn't get stuck. My best guess is that your code simply doesn't produce sound.
If that's the case, I could imagine it's due to the previous loop still being active. So maybe try adding the following to your speak() function:
ef speak(what):
print("Gosha: " + what)
try:
speak_engine.endLoop()
except Exception as e:
pass
speak_engine.say( what )
speak_engine.runAndWait()
speak_engine.stop()

python glob.glob not working any more, return an empty list

I am running in a very, strange case... Yesterday I wrote a little script. It's goal is to check one condition in a file based on another file. It worked as intended. But since this morning, it doesn't. I haven't changed anything to the best of my knowledge. the code doesn't throw any error. I think the culprit is glob.glob
for file in glob.glob('*private.vcf.gz'):
seen = False
vcf = VCF(file)
print("test")
if not (file == "controlH.g.vcf.gz" or file == "output.g.vcf.gz"):
sample_name = file.split('.')[0]
out = "{}.FalsePositiveRefCallPurged.vcf".format(sample_name)
w = Writer(out, vcf)
for v in vcf:
seen = False
ref = VCF('output.g.vcf.gz')
for r in ref:
if seen :
break
if not seen:
if v.CHROM == r.CHROM:
if v.start == r.start or v.start > r.start and v.start < r.end:
if r.FILTER == "RefCall":
continue#print(str(v))
else:
w.write_record(v)
seen = True
w.close()
Indeed, when simply running
glob.glob('.*private.vcf.gz')
I get an empty list.
Here is the output of bash
ls *.private.vcf.gz
D2A1.private.vcf.gz D3A1.private.vcf.gz D5B3.private.vcf.gz H2C3.private.vcf.gz H4C2.private.vcf.gz
D2B3.private.vcf.gz D4A3.private.vcf.gz H2A3.private.vcf.gz H4A4.private.vcf.gz H5A3.private.vcf.gz
So I am sure the files are there ... I really don't understand why suddenly glob.glob has troubles finding them.
Any help would be greatly appreciated, thanks
Ok, it appearst that a direactory
/.ipynb_checkpoints
was created and my notebook using it as its default directory...

Decode byte message in python3

I'm trying to decode this message below. For some reason I keep getting error. I tried everything on google but no success.
b'6362561400022,B,,\x00\x04\x14\x01\x0bPQ=\n\x15(3\x19\x1a<\x1e\x80\x00\x00\xc8\x04\r\xc6\xb1"\xc4\xf2D\xff\xcb\x02\x0c\xfe\x02\x00\x00\x00\nR\x00\x17\x00\x00\x00\x01'
UPDATE. Found the solution
int("0x" + ''.join([hex(x)[2:] for x in byte_string]), base=16)
Found the answer.
int("0x" + ''.join([hex(x)[2:] for x in byte_string]), base=16)

Resources