我一直在Python中工作,一直試圖移動字母表中的所有字母n空格,但是我遇到了相當多的錯誤。Python:在字符串中移動字母表中的字母
print("Cryptography")
userInput = str(input("Write anything that you'd like to encrypt here: "))
userNumberInput = int(input("Please choose a number without decimals here: "))
userInput = userInput.lower()
wordCount = userInput.split()
loopRunner = int(0)
letterCount = list()
for word in range(len(wordCount)):
letterCount.insert(loopRunner,len(wordCount[loopRunner]))
print(letterCount[loopRunner])
loopRunner = loopRunner + 1
outputString = "" .join((chr(97 + (ord(letter) -97 + userNumberInput) % 26) for letter in userInput))
loopRunner = 0
for word in range(len(wordCount)):
outputString2 = [outputString[i:i+letterCount[loopRunner]] for i in range (0, len(outputString), letterCount[loopRunner])]
loopRunner = loopRunner + 1
finalResult = " " .join(outputString2)
print(finalResult)
到目前爲止,它做什麼,我需要做的,但是當我嘗試運行此,它似乎也算位字母和我不知道如何將它們排除在外,同時保持他們在最後結果就像它們一樣。
另一件我想知道的事情是,如果有什麼辦法讓我不把字母變成小寫字母,並保持代碼的功能?
我一直在嘗試幾個小時的事情,但一直沒能找到一個好的解決方案。
你想改變的空間,以及或者只是改變信件並保留它們作爲空間的空間? –
我想改變這些字母並將它們作爲空格保留。我將如何去存儲空間的位置?我瞭解整個程序,但我不知道我在哪裏開始編碼。你能給我一個簡單的例子嗎? – Kei
我正在研究一個解決方案,但它的正確形式可能如下所示: 開頭: 保存列表中所有空格的索引位置 userInput = userInput.replace('','') and at結尾再次在這些索引位置添加空格。 –