Reputation: 31
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()
Trying to encrypt a string and add the odd and even character together but I keep getting this error. I have a file set up to be tested but it appears to not be working.
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()
Upvotes: 0
Views: 57
Reputation: 86798
You keep using str
(the name of the type representing a string) when you should be using fileContent
(the name of the variable containing your input string).
Upvotes: 1
Reputation: 30473
str
is a type (string, also you may think about it as about constructor), it's part of the language, and you don't have such variable. Maybe you want something like this:
for i in range(0, len(fileContent), 2):
Upvotes: 0