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
Artjom B.
  • 61,146
  • 24
  • 125
  • 222
Griffin Filmz
  • 101
  • 1
  • 2
  • 5

2 Answers2

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.

Joe Young
  • 5,749
  • 3
  • 28
  • 27
  • 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 07 '15 at 22:21
  • You're right. My apologies. Edited to reference the correct `join()` – Joe Young Sep 07 '15 at 22:33
  • okay but then how to you get it to look like qeb with the file as well – Griffin Filmz Sep 08 '15 at 00: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 08 '15 at 07:07
1

Maybe replace

key=[]

with

key=""

and replace

key.append(x)

with

key=key+x

?

Yannick
  • 139
  • 1
  • 7