Light Mode
Dark Mode
assertation error wrong data type

i used numpy module to solve this question and in final setp converted it to tuple of tuples but i get assertation eoor, the answer's value are correct for the three test cases given. Can anyone please guide me where should i look?

here's the code. Type call on the final result gives <type 'tuple'> too.

def make_list(final_ans): #make tuple of tuples form numpy array
    ans2,ans1=[],[]
    for aa in final_ans:
        for bb in aa:
            ans1.append(bb)
        ans2.append(ans1)
        ans1=[]
    ans3=tuple(tuple(row) for row in ans2)
    return(ans3)
def braille_page(text):
    #varible declerations
    letter_a,letter_b,letter_c,letter_d,letter_e,letter_f,letter_g,letter_h,letter_i,letter_j,letter_w,capital,number,char_1,char_2,char_3,char_4,char_5,char_6= numpy.array([[1,0],[0,0],[0,0]]),numpy.array([[1,0],[1,0],[0,0]]),numpy.array([[1,1],[0,0],[0,0]]),numpy.array([[1,1],[0,1],[0,0]]),numpy.array([[1,0],[0,1],[0,0]]),numpy.array([[1,1],[1,0],[0,0]]),numpy.array([[1,1],[1,1],[0,0]]),numpy.array([[1,0],[1,1],[0,0]]),numpy.array([[0,1],[1,0],[0,0]]),numpy.array([[0,1],[1,1],[0,0]]),numpy.array([[0,1],[1,1],[1,1]]),numpy.array([[0,0],[0,0],[0,1]]),numpy.array([[0,1],[0,1],[1,1]]),numpy.array([[0,0],[1,0],[0,0]]),numpy.array([[0,0],[1,1],[0,1]]),numpy.array([[0,0],[1,1],[0,0]]),numpy.array([[0,0],[1,0],[1,1]]),numpy.array([[0,0],[0,0],[1,1]]),numpy.array([[0,0],[1,1],[1,0]])
    letter_k,letter_l,letter_m,letter_n,letter_o,letter_p,letter_q,letter_r,letter_s,letter_t,letter_u,letter_v,letter_x,letter_y,letter_z=copy.deepcopy(letter_a),copy.deepcopy(letter_b),copy.deepcopy(letter_c),copy.deepcopy(letter_d),copy.deepcopy(letter_e),copy.deepcopy(letter_f),copy.deepcopy(letter_g),copy.deepcopy(letter_h),copy.deepcopy(letter_i),copy.deepcopy(letter_j),copy.deepcopy(letter_a),copy.deepcopy(letter_b),copy.deepcopy(letter_c),copy.deepcopy(letter_d),copy.deepcopy(letter_e)

    letter_k[2]=[1,0]
    letter_l[2]=[1,0]
    letter_m[2]=[1,0]
    letter_n[2]=[1,0]
    letter_o[2]=[1,0]
    letter_p[2]=[1,0]
    letter_q[2]=[1,0]
    letter_r[2]=[1,0]
    letter_s[2]=[1,0]
    letter_t[2]=[1,0]
    letter_u[2]=[1,1]
    letter_v[2]=[1,1]
    letter_x[2]=[1,1]
    letter_y[2]=[1,1]
    letter_z[2]=[1,1]
    blank=numpy.zeros((3,2),dtype=int)
    mappings=dict(zip(list('abcdefghijklmnopqrstuvwxyz,._?_!'),[letter_a,letter_b,letter_c,letter_d,letter_e,letter_f,letter_g,letter_h,letter_i,letter_j,letter_k,letter_l,letter_m,letter_n,letter_o,letter_p,letter_q,letter_r,letter_s,letter_t,letter_u,letter_v,letter_w,letter_x,letter_y,letter_z,char_1,char_2,char_3,char_4,char_5,char_6]))
    ans,i,flag=blank,0,False
#end of declerations
    ans=ans[:,2:] #initialize a 3X2 empty matrix
    bb=''
    for aa in text:
        bb=aa
        #if there are 10 chars in a line then insert  new blank line,and start ans computaion again so that ans can be appended to fianl_ans
        if ((i%10)==0)&(i!=0): #9 or 10

            ans=ans[:,:-1] #remove zero column delimeter
            (index_i,index_j)=ans.shape
            ans=numpy.vstack((ans,numpy.zeros((1,index_j),dtype=int))) #zero row matrix on 10 chars
            if i==10: #for 1st 10 letters
                final_ans=ans
            else: #for 20 letters onwards
                final_ans=numpy.vstack((final_ans,ans))
            if aa == text[-1]:
                final_ans=final_ans[:-1]
            ans=blank
            ans=ans[:,2:]
            i=0
            flag=True
        cap=re.search(r'[A-Z]',aa)
        num=re.search(r'[0-9]',aa)
        aa=aa.lower()
        if num: #insert sign of number and a zero column after it
            ans=numpy.hstack((ans,number))
            i+=1
            ans=numpy.hstack((ans,numpy.array([[0],[0],[0]])))
            aa=int(aa)
        if cap: # same as for num
            ans=numpy.hstack((ans,capital))
            i+=1
            ans=numpy.hstack((ans,numpy.array([[0],[0],[0]])))
        if aa in range(10):# conert a  number to letter represenataion as mappings only contains letters for eg- 1 to a and so on
            if aa=='0':
                aa=j
            else:
                aa=chr(96+aa)
        if aa==' ': #insert 2X3 zero array for blank or corrosponding matrix for letter
            ans=numpy.hstack((ans,blank))
        else:
            ans=numpy.hstack((ans,mappings[aa]))
        ans=numpy.hstack((ans,numpy.array([[0],[0],[0]]))) #insert zero column matrix for each symbols end
        i+=1
        if bool(bb==text[-1])&(i%10 !=0): # if all letters from string are computed
            ans=ans[:,:-1]
            if flag: #if 10 letters have completed then final_ans exists
                (final_i,final_j)=final_ans.shape
                (ans_i,ans_j)=ans.shape
                for ii in range(final_j-ans_j): #how many 0 column to insert for making rect matrix
                    ans=numpy.hstack((ans,numpy.array([[0],[0],[0]])))
                final_ans=numpy.vstack((final_ans,ans))
                return(make_list(final_ans))
            else:
                return(make_list(ans))
print(braille_page("hello 1st World!"))
Created: Jan. 25, 2018, 11:14 p.m.
Updated: Jan. 25, 2018, 11:38 p.m.
0
11
User avatar
gssanyam12