ColbySuns
发表于 2017-9-26 21:49:28
[技术交流] Python:每日一题 92(答题领鱼币)
timeislife
发表于 2017-9-30 06:46:27
本帖最后由 timeislife 于 2017-9-30 06:49 编辑
def bintype(number):
i = 0
g = []
f = 0
add_bin =
if number>255 or number<1 :
print("输入有误!")
else:
pass
while i<len(add_bin):
g.append(add_bin)
if sum(g) >number:
g.remove(add_bin)
i+=1
print(g)
while True:
try:
num = int(input("请输入要转换的数字"))
except ValueError:
print("请输入数字!")
bintype(num)
返回的是一个列表
美少女佳
发表于 2017-10-5 08:27:07
list0=
def fun(number):
if number==1:
print(1,end="");
elif number==2:
print(2,end="");
else:
list1=list0+
list1.sort()
order_number=list1.index(number)
y=list1-list1
fun(y);
print(" + " + str(list1),end="")
x=int(input("请输入一个1~255之间的数字:"))
fun(x)
{:10_269:}好像大家的算法都很简单我这个递归……
lh625243422
发表于 2017-10-5 08:44:52
学习下
776667
发表于 2017-11-2 15:47:13
def automatic_addition(x):
num_list =
result_list = []
for i in num_list:
if x >= i:
x -= i
result_list.append(str(i))
if x == 0:
return ' + '.join(result_list)
if __name__ == '__main__':
x = int(input('Enter a number between 1 to 255:'))
print(automatic_addition(x))
wangling
发表于 2017-11-3 15:56:21
看看别人的思路
shigure_takimi
发表于 2017-12-2 02:49:03
def fun(number):
a = [::-1]
factors = []
for i in a:
if number >= i:
factors.append(i)
number -= i
factors = sorted(factors)
return ' + '.join()
print(fun(3))
print(fun(155))
print(fun(8))
>>>
1 + 2
1 + 2 + 8 + 16 + 128
8
majia1015
发表于 2018-3-12 16:52:26
本帖最后由 majia1015 于 2018-3-12 18:12 编辑
def fun1(x):
list1 =
list2 = []
list3 = []
if (x >= 1) and (x <= 255):
for i in list1:
if x >= i:
list2.append(i)
x = x - i
list2.sort()
for x in list2:
list3.append(str(x))
print(' + '.join(list3))
else:
print('请重新输入数字,数字的范围是1~255')
昔日少年郎
发表于 2018-3-12 22:26:25
看看
新手潘包邮
发表于 2018-4-23 11:10:27
def fun(num):
num_list =
num1 = []
for i in range(len(num_list) - 1,-1, -1):
if num >= num_list:
num1.append(str(num_list))
num -= num_list
#print(num_list)
print("+".join(num1))
fun(253)
ABC23
发表于 2018-4-23 11:20:49
回复
duliping
发表于 2018-7-3 16:08:33
def fun(n):
x =
result = []
for each in reversed(x):
if n >= each:
result.append(str(each))
n -= each
return ' + '.join(list(reversed(result)))
hkjianvchf0
发表于 2018-7-19 16:38:17
学习了
no7line
发表于 2018-8-21 12:04:32
def fun(shuzi):
ans=[]
num=
for i in num:
if shuzi >= i:
shuzi = shuzi - i
ans.append(str(i))
ans.reverse()
return ' + '.join(ans)
c = input("请输入1-255之间的一个整数:")
shuzi = int(c)
d = fun(shuzi)
print("%d = "%shuzi + d)
兀颜光
发表于 2018-8-21 12:36:59
送
子沙
发表于 2018-8-27 21:21:49
本帖最后由 子沙 于 2018-8-27 21:35 编辑
def fun_92(m):
a=list(bin(m))
a.pop(0)
a.pop(0)
b=[]
print('%d='%(m),end='')
for i in range(len(a)):
if a=='1':
b.append(str(2**(len(a)-i-1)))
print('+'.join(b),end='')
fun_92(255)
战机智
发表于 2018-8-27 23:02:15
print("---------广告位出租-----------")
a=b=c=d=e=f=g=h='0'
num=input("请输入一个1-255的数字")
i=num
num=int(num)
if isinstance(num,int) and 1 <= num <= 255:
if num>128:
num=num-128
a='1'
if num>=64:
num=num-64
b='1'
if num>=32:
num=num-32
c='1'
if num>=16:
num=num-16
d='1'
if num>=8:
num=num-8
e='1'
if num>=4:
num=num-4
f='1'
if num>=2:
num=num-2
g='1'
if num>=1:
num=num-1
h='1'
print(a+"*128+"+b+"*64+"+c+"*32+"+d+"*16+"+e+"*8+"+f+"*4+"+g+"*2+"+h+"*1="+i)
else:
print("调皮哦")
45亿年后再见
发表于 2018-8-28 10:52:03
1
咕咕鸡鸽鸽
发表于 2019-3-5 17:59:50
def fun91(num):
list1 =
list2 = []
temp = num
for each in list1:
if temp >= each:
temp -= each
list2.append(str(each))
str1 = " + ".join(list2[::-1])[:-3] + " = " + str(num)
return str1
print(fun91(155))
776667
发表于 2019-4-9 11:44:43
from itertools import *
def fun92(x):
num =
for i in range(1,9):
for j in combinations(num,i):
if sum(j) == x:
result = ' + '.join()
return '%s = %s'%(result,x)
if __name__ == '__main__':
while True:
x = int(input('输入1-255整数:'))
if x < 1 or x > 255:
print('数值超出范围!')
else:
print(fun92(x))
break