Reputation: 55
I am currently working on a project with 'Encryption' at school, the first task is to do the following:
I would also like to say, I know there is not a message to encrypt currently, I am aware of this. This is just practice that needs to be done. Here is my code:
import random
key = ''
for i in range(0,8):
random_number = (random.randint(33,162))
str(chr(random_number.append(key)))
print(key)
print("Remember this key to decrypt your message!")
when inside of the shell (after running, I get the following error...)
"str(chr(random_number.append(key)))
AttributeError: 'int' object has no attribute 'append'"
Upvotes: 0
Views: 35
Reputation: 187
Try to do this:
import random
key = ''
for i in range(0,8):
random_number = (random.randint(33,162))
key += str(random_number) # main change
print(key)
print("Remember this key to decrypt your message!")
Upvotes: 0
Reputation: 5515
.append()
method is for list and list-like objects, not for simple, immutable types like int,str,tuple
etc. i think you wanted this:
key +=str(random_number)
instead to set key = key + str(random_number)
Upvotes: 1
Reputation: 139
You can only append to lists. You have an empty string to which you have to add. Now think which option we use with strings and you got it ;-)
Upvotes: 0