[Tutor] error in python code.

Danny Yoo dyoo at hashcollision.org
Wed Jun 22 00:16:07 EDT 2016


On Sun, Jun 19, 2016 at 10:38 PM, riaz tabassum <riaztbsm at gmail.com> wrote:
> Sir  i have a problem to solve to python code. I have attached the pic of
> problem statement.


Hi Riaz,

Often when you're asking a question, starting with presentation of the
code is often the wrong order to attack a problem.


The reason is because code just *is*.  It executes.  Although we can
often detect certain patterns that are bug prone (as Peter notes with
iterating over a dictionary), other than that, the code looks like it
does something.

It runs, so it must be right, right?

No, of course not.

But that's the part you need to explain, the "what" and the "why".


What makes code "good" or "bad" is human evaluation, some expectation
that we have about what we want to happen.  These expectations are
something that's usually stated in terms *outside* of the code.


Specifically, when you say these two parts:

> Test Dataset:
> CGCAGATGTTTGCACGACTGTGACAC


> Correct output:
>
> ['0', '-1', '0', '-1', '-1', '0', '0', '0', '1', '1', '1', '1', '2', '1',
> '1', '0', '1', '1', '0', '0', '1', '1', '2', '2', '1', '1', '0']

then the immediate question is: why should that be the correct output?
 Why those numbers?  To an untrained eye, it seems like an entirely
arbitrary, meaningless sequence.


What do the numbers mean?

We can't trust the code to look for meaning, because presumably the
code is broken.

So we need something else.

You need to state some definitions so that we are sharing common
terminology.  What does "skew" mean, for example?


If you can explain the problem well enough, we should be able to
compute the correct output by hand, without looking at your code.



Hope that makes sense.  Please feel free to ask questions.


More information about the Tutor mailing list