python - Converting string of ascii characters into their ascii numbers and assigning them to a variable -


i'm trying convert whatever user enters ascii numbers using method doesn't seem work , don't know problem is?

message = input ("enter message encrypted: ") message_numbers = ""  in message:     message_numbers1 = [ord(c) c in message]     message_numbers = message_numbers + message_numbers1  print (message_numbers) 

first of all, not need iterate on message , use list comprehension iterate again on message, stick one.

if expected output ascii numbers of characters entered input in string , missing converting list of ascii numbers string , can use string.join function -

message = input ("enter message encrypted: ")  message_numbers1 = [ord(c) c in message] message_numbers = message_numbers + ''.join(map(str, message_numbers1))  print (message_numbers) 

please note, input join function iterable list_like of strings , hence converted message_numbers1 string using map .

if message_numbers1 not used anywhere else, can directly create strings in it, below -

message_numbers1 = [str(ord(c)) c in message] 

in case, can directly use -

message_numbers = message_numbers + ''.join(message_numbers1) 

Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

Kivy: Swiping (Carousel & ScreenManager) -