-2

I'm creating a encryption program in Python where user will input like <<< This is the text which is decrypted! How can I show the result as output? Is there any way to split "This is the text which is decrypted!" into different variables value by length? Like:

input_list=input.split(len(8))
for i in input_list:
    input+n=i. #string
    n +=1

And it will turn:

input1="This is " 
input2=" the text" 
input3=" which is" 
input4=" decrypted"
input5="!"
print (input1+input2+input3+....)

And the output will show the the same text as inputted

Ratul Hasan
  • 544
  • 6
  • 14
  • Possible duplicate of [Split string into strings by length?](https://stackoverflow.com/questions/13673060/split-string-into-strings-by-length) – Tomerikoo Jul 20 '19 at 16:46
  • 1
    Possible duplicate of [How do I create a variable number of variables?](https://stackoverflow.com/questions/1373164/how-do-i-create-a-variable-number-of-variables) – ggorlen Jul 20 '19 at 17:01

1 Answers1

1

The closest I can come up with is by using a list or dictionary, for example(with a list):

input = "This is the text which is decrypted!"
output = []
length = 8
for i in range(len(input))[::length]:
    output.append(input[i:i+length])
print(output[0])
print(output[1])
#...
Vincc
  • 86
  • 5
  • 1
    Could be written simpler as `range(0, len(input), length)`. And then even transformed to a list comprehension: `output = [input[i:i+length] for i in range(0, len(input), length)]`. *But*, it's important to point out that `input` shouldn't be used as a variable as it is a built-in name. – Tomerikoo Jul 21 '19 at 06:39
  • Yep, I apologize for the bad variable naming =.= – Vincc Jul 21 '19 at 11:34