def main():
inFile = open ('input.txt', 'r')
fileContent = inFile.read()
choice = input('Do you want to encrypt or decrypt? (E / D): ')
for i in fileContent:
if (choice == 'E'):
for i in range(0, len(str), 2):
even_str = str[i]
for i in range(1, len(str), 2):
odd_str = str[i]
outFile = open("output.txt", "w")
outFile.write(even_str)
outFile.write(odd_str)
outFile.write(encrypted_str)
print('even_str = ',even_str)
print('odd_string = ',odd_str)
print('encrypted_str = ',encrypted_str)
outfile.close()
if (choice != 'E' and choice != 'D'):
print ('')
print ('Wrong input. Bye.')
return
inFile.close()
main()
尝试加密字符串并将奇数和偶数字符加在一起但我不断收到此错误。我有一个文件设置要测试,但似乎无法正常工作。
Traceback (most recent call last):
File "C:/Python33/CS303E/Cipher.py", line 41, in <module>
main()
File "C:/Python33/CS303E/Cipher.py", line 24, in main
for i in range(0, len(str), 2):
TypeError: object of type 'type' has no len()
答案 0 :(得分:1)
当您使用str
(包含输入字符串的变量的名称)时,您继续使用fileContent
(表示字符串的类型的名称)。
答案 1 :(得分:0)
str
是一个类型(字符串,你也可以把它想象成构造函数),它是语言的一部分,你没有这样的变量。也许你想要这样的东西:
for i in range(0, len(fileContent), 2):