使用重复的部门如何十进制转换为二进制通过使用Python中反复分裂?如何十进制转换为二进制在蟒蛇
我知道我必须使用while循环,并使用模数标志和其他{%}和{//}要做到这一点......但我需要某种形式的例子,我的理解它是如何完成的,所以我完全可以理解。 指正,如果我错了:
number = int(input("Enter a numberto convert into binary: "))
result = ""
while number != 0:
remainder = number % 2 # gives the exact remainder
times = number // 2
result = str(remainder) + result
print("The binary representation is", result)
break
谢谢
您是否收到任何错误? – hdost
正确的pep8格式 –