使用重複的部門如何十進制轉換爲二進制通過使用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格式 –