-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)
4

1 回答 1

3

OPT 返回 none 的原因是因为您返回了 print 函数的返回结果 -

return print("".join(m))

这确实是无。要获取字符串,您应该这样做 -

return "".join(m)
于 2013-10-22T10:40:29.967 回答