我一直在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结尾再次在这些索引位置添加空格。 –