您好我有问题,因为此功能会创建我想要的数字,但也会生成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)
答案 0 :(得分:3)
OPT返回none的原因是因为您返回打印函数的返回结果 -
return print("".join(m))
确实没有。要获得你应该做的字符串 -
return "".join(m)