北城以北灬
发表于 2019-3-15 11:13:12
import itertools
count = 0
for list1 in itertools.permutations(range(1, 10), 3):
if sum(list1) == 15:
print(list1)
print()
count += 1
print(count)
dograss
发表于 2019-3-15 15:02:34
看看课后题
hj5818
发表于 2019-4-13 23:33:18
list1 =
for i in list1:
for j in list1:
for k in list1:
if i + j + k == 15:
print (i,"+",j,"+",k,"= 15")
野外生存
发表于 2019-4-14 08:07:02
看不懂
liduo0413
发表于 2019-4-14 14:25:37
{:7_130:}
yu123py
发表于 2019-4-29 13:43:00
好像有点繁琐
l = []
for i in range(1,10):
for j in range(1, 10):
for k in range(1, 10):
if i + j + k == 15:
l.append(sorted())
l1 = []
for t in l:
if t not in l1:
l1.append(t)
print(l1)
一只米尼
发表于 2019-6-20 17:44:18
学习学习
549491637
发表于 2019-6-27 07:49:18
a=[ for x in range(1,10) for y in range(1,10) for z in range(1,10) if x != y != z and x+y+z == 15]
for i in a:
print("%d%d%d"%(i,i,i))
做了个短的,不过效率可能不高
阳顺
发表于 2019-6-27 11:48:51
那先看看题啊
xxttww
发表于 2019-6-27 16:14:50
学习{:5_109:}
克里斯保罗
发表于 2019-9-3 08:06:17
for a in range(1,10):
for b in range(1,10):
for c in range(1,10):
if a+b+c == 15 and a!=b and a!=c and b!=c:
print('结果是%d %d %d'%(a,b,c))
wlf6110263
发表于 2019-9-3 14:27:15
a = 1
while a < 10:
b = 1
while b < 10:
c = 1
while c < 10:
if a + b + c ==15:
print(a, b, c, "加起来等于15")
c = c +1
b = b+ 1
a = a + 1
Jung
发表于 2019-12-3 13:52:23
import itertools as A
B = A.permutations(range(1,10),3)
for i in B:
if sum(i)==15:
print(i)
wening
发表于 2019-12-3 17:54:23
list1 = list(range(1,10))
for i in range(0,9):
for j in range(i+1,9):
for k in range(i+2,9):
if list1 + list1 + list1 == 15:
if list1 != list1 and list1 != list1 and list1 != list1:
list2 = sorted(,list1,list1])
print('the sequence is %s'%list2)
else:
pass
else:
pass
verauxu
发表于 2019-12-29 11:36:50
count=0
for a in range(1,10):
for b in range(1,10):
for c in range(1,10):
if a+b+c == 15:
if a!=b and a!=c and b!=c:
print(a,b,c)
count+=1
print('共有%d种可能'%count)
华一仙
发表于 2020-2-27 17:35:17
"""
个人拙见:
1. 数字可重复使用,如 (5, 5, 5)
2. (4, 5, 6) 与 (6, 5, 4) 为一种解
令左、中、右(单调不减)三个数字为 l, m, r
/ l + m >= 15 - 9 => m >= 3
| => 3 <= m <= 7=> m = 5 时,l 取得最大值 5
\ m + r <= 15 - 1 => m <= 7
r 可由 15 - l - m 得到
"""
def solve():
cnt = 0
for m in range(3, 8):
for l in range(1, 6):
r = 15 - l - m
if r > 9:
continue
elif r < m or m < l:
break
else:
cnt += 1
print(f"No.{cnt:0>2}: {l} {m} {r}")
海上飞鱼
发表于 2020-3-1 18:20:08
list1 = []
for x in range(1,10):
for y in range(1,10):
z = 15-x-y
if 0 < x < y < z < 10:
list1.append()
print(f'共有{len(list1)}种组合:', list1)
catwine1990
发表于 2020-3-12 21:20:41
{:5_90:}
bensonlin
发表于 2020-3-12 21:39:32
本帖最后由 bensonlin 于 2020-3-12 21:43 编辑
for a in range(1,8):
for b in range(1,(15-a)//2+1):
print(a, b, 15-a-b)
运行结果:(1, 1, 13)
(1, 2, 12)
(1, 3, 11)
(1, 4, 10)
(1, 5, 9)
(1, 6, 8)
(1, 7, 7)
(2, 1, 12)
(2, 2, 11)
(2, 3, 10)
(2, 4, 9)
(2, 5, 8)
(2, 6, 7)
(3, 1, 11)
(3, 2, 10)
(3, 3, 9)
(3, 4, 8)
(3, 5, 7)
(3, 6, 6)
(4, 1, 10)
(4, 2, 9)
(4, 3, 8)
(4, 4, 7)
(4, 5, 6)
(5, 1, 9)
(5, 2, 8)
(5, 3, 7)
(5, 4, 6)
(5, 5, 5)
(6, 1, 8)
(6, 2, 7)
(6, 3, 6)
(6, 4, 5)
(7, 1, 7)
(7, 2, 6)
(7, 3, 5)
(7, 4, 4)
37种
bensonlin
发表于 2020-3-12 21:46:01
我这是第一次答题
你这答案不对啊,1+7+7 和7+1+7和7+7+1反复出现了。