我想写一个凯撒密码,但比正常情况下更难。实际的加密是在一个文件上,然后被分割成几行。对于每一行,我希望在开始,中间和结束之前添加一个单词,然后再进行转换。到目前为止,我有这一点,但它不工作:如何找到字符串的中间插入一个词
file = str(input("Enter input file:" ""))
my_file = open(file, "r")
file_contents = my_file.read()
#change all "e"s to "zw"s
for letter in file_contents:
if letter == "e":
file_contents = file_contents.replace(letter, "zw")
#add "hokie" to beginning, middle, and end of each line
lines = file_contents.split('\n')
def middle_message(lines, position, word_to_insert):
lines = lines[:position] + word_to_insert + lines[position:]
return lines
message = "hokie" + middle_message(lines, len(lines)/2, "'hokie'") + "hokie"
我越来越
TypeError: slice indices must be integers or None or have an __index__ method
我在做什么错了,我还以为LEN()返回一个int?
在Python 3.x,'len(lines)/ 2'可能不是一个整数... – jonrsharpe