1
def main():
 key = []

 mess=input('Write Text: ')

 for ch in mess:
     x = ord(ch)
     x = x-3
     x = chr(x)
     key.append(x)

 print("Your code message is: ",key)

 outFile = open("Encryptedmessage.txt","w")
 print(key, file=outFile)

main()

so far i have written this a it works fine but my problem is the output is

Write Text: the
Your code message is:  ['q', 'e', 'b']

and i was wondering how you would get rid of the punction so the output would be

Write Text: the
Your code message is:  qeb
1
  • 1
    Shouldn't the duplicate flag point to a question that is not itself a duplicate? :-)
    – alexis
    Sep 7, 2015 at 22:23

2 Answers 2

2

key is a list. You can use join(list) to join the elements of the list together:

print("Your code message is: ", "".join(key))

str.join(iterable)

Return a string which is the concatenation of the strings in the iterable iterable. The separator between elements is the string providing this method.

Source: https://docs.python.org/2.7/library/stdtypes.html?#str.join

You don't want any separator characters in between the elements of the list, so use an empty string "" as the separator.

4
  • 2
    You're mixing up the string method join() with join from the (mostly) obsolete string module. "".join has no sep argument, nor does it need one.
    – alexis
    Sep 7, 2015 at 22:21
  • You're right. My apologies. Edited to reference the correct join()
    – Joe Young
    Sep 7, 2015 at 22:33
  • okay but then how to you get it to look like qeb with the file as well Sep 8, 2015 at 0:14
  • Assign the output of the join to a variable. For example: joinedkey="".join(key). Use that variable (i.e. joinedkey) in place of key in your print statements. For example: print(joinedkey, file=outFile)
    – Joe Young
    Sep 8, 2015 at 7:07
1

Maybe replace

key=[]

with

key=""

and replace

key.append(x)

with

key=key+x

?

Not the answer you're looking for? Browse other questions tagged or ask your own question.