|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 宇宙哥哥 于 2020-8-16 15:44 编辑
def Dec2Bin(dec):
result = []
if dec:
result = Dec2Bin(dec//10)
return result + list(dec%10)
else:
return result
print(Dec2Bin(12345))
为什么用这个方法不行 求大佬详解
正确方法这个
result = []
def get_digits(n):
if n > 0:
result.insert(0, n%10)
get_digits(n//10)
get_digits(12345)
print(result)
我知道 我就是想知道那个问题出在哪里 谢谢
- def Dec2Bin(dec):
- result = []
-
- if dec:
- result = Dec2Bin(dec//10)
- return result + [dec%10]
- else:
- return result
- print(Dec2Bin(12345))
复制代码
|
|