[Tutor] error in python code.

riaz tabassum riaztbsm at gmail.com
Mon Jun 20 01:38:19 EDT 2016


Sir  i have a problem to solve to python code. I have attached the pic of
problem statement.
code which i write is pasted here.
"def Skew(Genome):
    skew = {}
    #initializing the dictionary
    skew[0]=0#initializing the dictionary

    for i  in  range(len(Genome)):
          if i==0:

              if Genome[i]=='G':

                  skew[i]=skew[i]+1
              elif Genome[i]=='C':

                   skew[i]=skew[i]-1
              else:

                  skew[i]=skew[i]


          elif Genome[i]=='G':

               skew[i]=skew[i-1]+1


          elif Genome[i]=='C':
              skew[i]=skew[i-1]-1

          else:
              skew[i]=skew[i-1]
    # your code here
    return skew


Genome="CGCAGATGTTTGCACGACTGTGACAC"
print Skew(Genome).values()

#Sample 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'
"


But i am facing the problem that  i could not  include the first index
which is initialized to zero in my answer.


the error is shown as

Failed te #2.

Test Dataset:
CGCAGATGTTTGCACGACTGTGACAC

Your output:
['-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']

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']


More information about the Tutor mailing list