1

I tried looking up a previous question but nothing popped up. My professor wants us to create a program with Python that can convert Binary back to Text, by entering one byte at a time. I tried to use the following code, but my accumulator keeps failing to work. Do you have any idea what I'm doing wrong?

def main():

    length = int(input('How many characters would you like to convert with binary?'))

    accu = ''

    for i in range(length):

        binary = input('Enter some binary and I will make it into text: ')
        base = int(binary, base = 2)
        decoded = chr(base)
        print(decoded)
        decoded + str(accu)        

    print(accu)

main()
1
  • Could you provide us an example of input and it's repectively expected output? Also, at first glance, how do you expect see something in variable accu without storing anything in it? You are just initializing it with a empty string and the value of decoded + str(accu) is not beeing stored anywhere... Commented Sep 28, 2018 at 0:47

1 Answer 1

1

You have the problem because you do not save result of adding newly decoded symbols to accu. Change the line decoded + str(accu) with the line accu += decoded. This will allow you to save all the decoded symbols into a single string accu.

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