我现在有这个代码,但它并没有打印任何东西,我对如何做到这一点感到非常困惑。
def vigenere(key, letter):
keyVal = ord(key)
letterVal = ord(letter)
keyVal = keyVal - 97
letterVal = keyVal + letterVal
if letterVal >= ord("z"):
letterVal = letterVal - 26
print letterVal
答案 0 :(得分:1)
你必须在循环中为字符串执行此操作,就像我在下面所做的那样:
def vigenere(key, letter):
letterChar = ""
for i in range(len(letter)):
keyVal = ord(key)
letterVal = ord(letter[i])
keyVal = keyVal - 97
letterChar += chr(keyVal + letterVal)
if letterVal >= ord('z'):
letterVal = letterVal - 26
print letterChar
vigenere('c', "pop")
它返回:
rqr