2016-04-28 33 views
1

此代碼將十進制轉換爲二進制,同時仍需要反轉以顯示正確的數字。將生成的整數轉換爲垂直列表和反向列表順序

dec = int(input("Please enter number to convert to decimal: ")) 
while dec>0: 
    quoteint = dec/2 
    rem = dec%2 
    print (int(rem)) 
    dec = int(dec/2) 

我在找一行代碼來顯示下面的代碼。例如

1 0 0 1 0 0 

但代碼目前只產生在這樣的行中的整數。

1 
0 
0 
1 
0 
0 

我知道我需要把整數變成一個列表,然後顛倒列表讓它顯示正確的二進制數。有人可以解釋我怎麼可能做到這一點?

回答

0

我想,如果你改變了行

print (int(rem))

print (int(rem), end="")應該做的工作。

+0

(即包括一個逗號和結束=「」) – fierynot

+0

這樣做。非常感謝。 –