有人可以帮我弄清楚如何将加密句子的所有字母保持在同一行。该代码有效,虽然很长哈。
sentence = raw_input('Enter a sentence to be encrypted ')
shift = input('Enter a shift value ')
def createDict (shift):
alphabet = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ .,'
alphaList=[]
for letter in alphabet:
alphaList.append(letter)
alphaDict={}
for letter in alphaList:
valueLetterIndex = (alphaList.index(letter) + shift)%len(alphaList)
valueLetter = alphaList[valueLetterIndex]
alphaDict[letter] = valueLetter
return alphaDict
def encryptText(sentence, shift):
dict = createDict(shift)
for letter in sentence:
encryptC = dict [letter]
print encryptC
print encryptText(sentence, shift)