谁动了我的豆包
发表于 2017-9-10 12:16:56
def fun(num):
result = []
list1 =
i = len(list1)
while i > 0 and num > 0:
if num >= list1:
result.append(list1)
num -= list1
i -= 1
else:
i -= 1
print(' + '.join(str(i) for i in result))
sunnychou
发表于 2017-9-11 08:34:37
{:5_91:}
一条小鱼儿
发表于 2017-9-11 19:17:04
def fun(num,list_2=[]):
list_1 =
if num not in list_1:
list_1.append(num)
list_1.sort()
m = list_1
list_2.append(m)
return fun(num - list_1,list_2)
else:
list_2.append(num)
list_2.reverse()
print('+'.join(str(i) for i in list_2))
lihuayuan
发表于 2017-9-11 19:38:20
啊哈
Linco
发表于 2017-9-11 22:05:49
def fun(num):
nums =
res = []
for j in range(8):
i = num & 0x01
num = num >> 1
if i == 1:
res.append(str(nums))
return ' + '.join(res)
Jailz
发表于 2017-9-12 15:28:29
1
985330354
发表于 2017-9-12 15:55:23
学习
zers
发表于 2017-9-12 16:32:39
svdsv
萎苕
发表于 2017-9-12 19:26:19
def fun(num):
return "+".join(i for i,j in zip(['1','2','4','8','16','32','64','128'],bin(num)[-1:1:-1]) if int(j))
林一
发表于 2017-9-14 08:47:35
def fun(num):
return "+".join(i for i,j in zip(['1','2','4','8','16','32','64','128'],bin(num)[-1:1:-1]) if int(j))
upc-xiaoxiao
发表于 2017-9-17 17:16:17
学习
助人为乐的乐为
发表于 2017-9-19 20:49:10
return'+'.join(s)什么意思啊?
SuperBoy007
发表于 2017-9-20 11:19:34
def fun(num):
List=
Result=[]
for each in List:
if num>=each:
num-=each
Result.append(str(each))
return '+'.join(Result)
jack_xy
发表于 2017-9-25 17:33:14
def funB(num):
#递归方法实现将10进制转为2进制
if num==0:
return ""
else:
if num%2==1:
return funB(num//2)+"1"
else:
return funB(num//2)+"0"
def fun(n):
factor=
prompt=""
#将2进制数转发成要求的输出格式
for each in zip(reversed(funB(n)),factor):
if each=='1':
if len(prompt)>0:
prompt=prompt+" + "+str(each)
else:
prompt=str(each)
return prompt
Qking
发表于 2017-9-25 21:52:09
。。。
Qking
发表于 2017-9-25 21:52:52
楼主是我偶像好厉害
Liuyl
发表于 2017-9-26 13:02:50
应该要用递归,但是函数写出来有问题,先看看答案
Liuyl
发表于 2017-9-26 16:30:35
递归实现:
list=
list1=[]
str1='+'
def fun(a):
for x in list:
if(x<a and x*2>a)or x==a:
b=a-x
list1.append(x)
break
if b!=0:
fun(b)
else:
print(str1.join(str(n)for n in list1))
了解2号
发表于 2017-9-26 19:01:33
{:5_90:}
ColbySuns
发表于 2017-9-26 21:49:28
[技术交流] Python:每日一题 92(答题领鱼币)