0
hexadecimal = 0
while hexadecimal_ != '000':
    if hexadecimal_ == '000':
        print("End of Program")
    else:
        hexadecimal_ = input("Enter Hexadecimal: (0-7F) (Enter '000' to erminate program)")

        if hexadecimal_ == '0':
           print("(NULL)")
        elif hexadecimal_ == '1':
           print("(Start of Header)")          
        elif hexadecimal_ == '2':
           print("(Start of Text)")

I'm only in high school and started learning python about 2 weeks ago, and was wondering how I'd be able to run this program (which translates hexadecimal into characters) and insert a number (e.g 61) and it would be inserted into a list (translated) much like .append but it would be hidden until I ended the program.

Being able to view the list once the program ended or perhaps during the program. If possible is the list able to be a single line (e.g. If I typed 48(H) 49(I) 20(space) 57(W) 41(A) 4C(L) 4C(L) and instead of [H, I, (space), W , A , L, L] it would come out as HI(space)WALL)?

Thank you for your time.

Patrick Haugh
  • 59,226
  • 13
  • 88
  • 96
  • Provided that you didn't actively call `print` on the list until the very end then `append` would not show the list every time you appended to it during execution. I'm not clear on that part of your question. – roganjosh Feb 12 '18 at 22:32
  • It looks to me as if you're concatenating to a string, rather than to a list. The conglomeration in your final sentence is the `join` method. Look on-line (e.g. on Stack Overflow) for how you build up a string or a list; this is covered in many other places. If you get stuck, come back here with the specific problem. – Prune Feb 12 '18 at 22:35

2 Answers2

1

What you could do is append the hexadecimal_ entries to a list and then, after the while loop is broken, print out the elements in that list using the .join method. Like so:

list = []

while hexadecimal_ != '000':

    hexadecimal_ = input("Enter Hexadecimal: (0-7F) (Enter '000' to erminate program)")

    if hexadecimal_ == '000':
    break()

    elif hexadecimal_ == '0':
       print("(NULL)")
    elif hexadecimal_ == '1':
       print("(Start of Header)")          
    elif hexadecimal_ == '2':
       print("(Start of Text)")

    list.append(hexadecimal_)

print(''.join(list))

''.join() takes an argument at the front between the quote marks - this is your separator - and an argument at the back between the brackets - this is the list to join. See here: Concatenate item in list to strings

PeptideWitch
  • 2,239
  • 14
  • 30
0

he best way to go about it is

print(''.join(lst))

based on comments by @roganjosh

Another way to do it (but not recommended):

For python 3

for item in lst:
    print(item,)
print('\n')

For python 2

for item in lst:
    print item,
print '\n'

This does add whitespace inbetween the characters.

Nathan
  • 3,558
  • 1
  • 18
  • 38