2013-10-22 54 views
-2

嗨我有問題,因爲此功能創建我想要的數字,但也產生None。我應該怎麼寫這段代碼不會產生NONE如何讓這個功能不消失?

def binary (str): 
    b = [] 
    for x in str: 
     b.append(format(ord(x), 'b')) 
    return ((b)) 
clave = "1001001000010001001000110111111100110000100011001010100000110001110110011111010010011111000011111001000011101011001101000001110010011110010110000000" 

c = list(clave) 
msg = binary("Lol") 
print("".join(msg)) 
m = list("".join(msg)) 
print("Now the right") 

def OTP(m,c):  
    for i in range (0,len(m)): 
     if c[i]== "1" and m[i]== "1": 
      m.pop(i) 
      m.insert(i,"0") 
     elif c[i] == "1" and m[i] == "0": 
      m.pop(i) 
      m.insert(i,"1") 
    return print("".join(m)) 

msg1 = OTP(m,c) 
print(msg1) 
+1

這不可能是你的代碼:一旦我固定的縮進你,你可以從你有一條線一個無與倫比的報價高亮看到。請複製並粘貼您的實際代碼。 – Duncan

+2

出於好奇 - 你和拉斐爾在同一課程? http://stackoverflow.com/questions/19497000/list-index-out-of-range-error –

回答

3

的OPT理由退換貨沒有一個因爲您返回打印函數的返回結果 -

return print("".join(m)) 

這確實無。要獲取字符串你應該只是做 -

return "".join(m)