I want to create a program that can convert numbers to binary. I am aware of the bin() function, however I want to use the method that involves dividing the number until its zero by 2 and noting the remainders. The problem I have is that I need to divide until it equals zero. I do not think there is a way to get a result of a mathematical operation inside a while loop and then substitute/use it in the that same code. I don’t think I actually explained this very well, I hope you understand.
while True:
print("Enter your number: ")
num = int(input())
status = True
while status == True:
quotient = num // 2
remainder = num % 2
print(quotient)
print(remainder)
if quotient == 0:
status = False
else:
status = True
echo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.