2進制裝換10進制
l1 = int(input(‘請輸入要轉換的10進制數:’))
l2 = []
print(‘YSF出品’)
print(‘ysfcn.website’)
print(‘萬水青山總是情,點個關注行不行!’)
定義兩個函數q1,q2
def q1(l1):
while l1 % 2 == 1: #
while l1 == 1:
l2.insert(0, 1)
print('結果在這:', l2)
exit()
while l1 % 2 == 1:
l2.insert(0, 1) # 如果l1%2等於0,則列表l2索引0處添加0
l1 //= 2 # l1=l1/2
if l1 == 1:
break
else:
l2.insert(0, 0) # 如果l1%2不等於0,則列表l2索引0處添加1
l1 //= 2 # l1=l1/2
else:
q2(l1)
def q2(l1):
while l1 % 2 == 0:
l2.insert(0, 0) # 如果l1%2不等於0,則列表l2索引0處添加1
l1 //= 2 # l1=l1/2
else:
q1(l1)
while l1 % 2 == 1: # debug 在這裏斷點
q1(l1)
else:
q2(l1)