-2

Hi there i am trying to put a user input into an array, so far i have:

#Decrypt string
def decrypt():
    print("Please enter code to be decrypted.")
    text = input(">>>")
    print("Please enter your key used to encrypt the data.")
    key = int(input(">>>"))



    #Put input into array
    #????

I am tring to get the input and put it in an array so that it can be referenced using

chr(text[1])

To convert it into plain text from ascii (Basic encryption and decryption). I have found a few posts on this but they are outdated (for python2 etc...).

Thanks!

7
  • 1
    text[1] should already work regardless of Python2 vs Python3... Commented Jun 17, 2016 at 20:23
  • Possible duplicate of How to get char from string by index? Commented Jun 17, 2016 at 20:25
  • @cricket_007 It does work, i just want to be able to refence it from the users input like you would from an array. Commented Jun 17, 2016 at 20:26
  • @TadhgMcDonald-Jensen i cant use that solution because some elements will be 3 letters long and i wont know what to select i also just want it as an int in a array. Commented Jun 17, 2016 at 20:29
  • show me an answer that didn't work for you because you are using python3. I don't see how it would be different between versions. Commented Jun 17, 2016 at 20:32

1 Answer 1

0

If you just want to have an indexable list to store user inputs as they come in, you can use the built-in list class and its append method:

keys = list();
texts = list();

def decrypt():
  print("Please enter code to be decrypted.")
  text = input(">>>")
  print("Please enter your key used to encrypt the data.")
  key = int(input(">>>"))
  texts.append(text)
  keys.append(key)

Now, texts[n] will return the nth text value entered by your user.

Sign up to request clarification or add additional context in comments.

1 Comment

Sorry i didn't see this but i just used text1 = text.split() since the input comes with spaces and it works a charm, thanks though!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.