Reputation: 667
i'm trying to format this better so it prints out as one block of text (spaces are ok)
right now it's printing like this [4444, 4444] and i want it to print 4444 4444
#secret code encrypter
def encoder(plain):
'''encodes a given input with a secret formula
'''
result = []
for i in plain:
i=ord(i)*77+4
result.append(i)
return result
def main():
plain=input('Enter a sentence: ')
final=encoder(plain)
print(final)
main()
Upvotes: 0
Views: 311
Reputation: 142136
Make them strings and join them:
print(' '.join(map(str, your_list)))
Even better (if you're using Python 3.x) to avoid explicit conversion:
print(*your_list)
Upvotes: 7
Reputation: 5467
Borrows from what others pointed out from my comments adds something many have missed that was previously in one of the answers:
(For pre python 3.0:) You will want to use raw_input
instead of input
because you just want to capture not evaluate.
Per 2.7.5 docs:
input(prompt)
is equivalent toeval(raw_input(prompt))
Printing ( mostly lifted from Jon C's answer) Make them strings and join them:
print(' '.join(map(str, your_list)))
Even better (if you're using Python 3.x) to avoid explicit conversation:
print(*your_list)
Upvotes: 0
Reputation: 308130
Based on your comment to an earlier answer, you need this:
print(' '.join(str(x) for x in final))
This converts each of the elements in final
to a string before joining them with a space between.
Upvotes: 2
Reputation: 7236
Try this:
print(" ".join(list_you_want_to_print))
str.join(iterable)
will return a string with the items in the utterable separated by the string.
Upvotes: 1
Reputation: 35793
If I get what your trying to do, try this:
print(" ".join(map(str, final)))
Upvotes: 4