2

I'm creating a string which is returned from the function. I need the string to list some values.

I have created a list which is joined at the end to make the complete string. I'm trying to add a new line on each iteration in the while loop the list is appended to.

while shiftAmount < 25: #Iterates through all 26 combinations producing a processed value each time.
    shiftAndStore(shiftAmount)
    shiftAmount = shiftAmount + 1
    stringshift = str(shiftAmount)
    outputCipherText.append("The Encoded / Decoded text on shift " + str((shiftAmount - 1)) + " is ")
    outputCipherText.append(str(''.join(completePlainText)) + " \n")
    completePlainText = []
output = [''.join(outputCipherText)]

Can anyone tell me why this is not working? looking at the output it shows the \n but doesn't execute it and make a new line.

2
  • What kind of object is outputCipherText? Commented Nov 3, 2012 at 16:22
  • @enrico.bacis: It looks like it's a list. Commented Nov 3, 2012 at 16:46

3 Answers 3

2

The problem is that you are not printing a string but a list of strings. The line

output = [''.join(outputCipherText)]

is adding a single string to a list. That look useless to me, you can simply change it with:

output = ''.join(outputCipherText)

to obtain a string, and not a list containing only one string. After that change you can use print output and all the special characters will be executed, so the \n characters will be shown as newlines.

If you don't want to change your code, you have to print the string and not the list of strings:

print output[0]
Sign up to request clarification or add additional context in comments.

Comments

0

Please correct me if i'm wrong but i think you don't have to include this outputCipherText.append(str(''.join(completePlainText)) + " \n") and completePlainText = []. You can directly output the outputCipherText with newline after the loop with output = '\n'.join(outputCipherText) and call print(output)

Comments

0

Put:

    output.append(''.join(outputCipherText))

at the end of the while loop and remove the output = [''.join(outputCipherText)] folowing it.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.