Feb-18-2019, 11:55 PM
I'm working on an assignment that converts decimal to binary. For each loop it's supposed to print the working number and the remainder (0 for even, 1 for odd), and then print the full binary number at the end.
For the most part I've got it working, but I'm stuck. I've got this print line at the bottom that needs to print once the working number reaches zero. I don't want it to print if the user enters zero. Only if the loop ends in zero. I've tried all kinds of indenting, I've tried switching around the order. I'm just stumped.
Any help is appreciated!
Also, for this assignment I'm not allowed to use list()function, reversed()function, string indexing, for loops or .split()method.
For the most part I've got it working, but I'm stuck. I've got this print line at the bottom that needs to print once the working number reaches zero. I don't want it to print if the user enters zero. Only if the loop ends in zero. I've tried all kinds of indenting, I've tried switching around the order. I'm just stumped.
Any help is appreciated!
Also, for this assignment I'm not allowed to use list()function, reversed()function, string indexing, for loops or .split()method.
binary = '' working = int(input('Enter a positive number: ')) while working >= 0: if working == 0: break remainder = working % 2 print(working, '', str(remainder) + binary) if working % 2 == 0: remainder = 0 else: remainder = 1 working = working // 2 binary = str(remainder) + binary print('Your decimal number in binary is ' + binary)Thank you!