清风揽月shine
发表于 2017-4-15 15:25:16
n=0
temp=[]
a=input('num:')
b=input('num:')
c=input('num:')
d=input('num:')
temp.append(a)
temp.append(b)
temp.append(c)
temp.append(d)
for x in temp:
for y in temp:
for z in temp:
if (x!=y)and(x!=z)and(y!=z):
print(x,y,z)
n+=1
print('In total %d types'%n)
源稚空
发表于 2017-4-17 21:18:52
for a in range(1,5):
for b in range(1,5):
for c in range(1,5):
if a!=b and b!=c and a!=c :
print (a,b,c)
seasonjj
发表于 2017-4-18 11:57:47
for a in list(range(1,5)):
for b in list(range(1,5)):
for c in list(range(1,5)):
if a != b and b != c and a != c:
num = 100*a + 10* b + c
print(num)
solomonxian
发表于 2017-4-18 20:08:09
两两不相等,不试下用集合吗?
数字多起来的时候还是集合好用吧
for i in range(1,5):
for j in range(1,5):
for k in range(1,5):
if len({i,j,k}) == 3:
print(100*i+10*j+k)
else: return
有益
发表于 2017-4-29 08:19:58
solomonxian 发表于 2017-4-18 20:08
两两不相等,不试下用集合吗?
数字多起来的时候还是集合好用吧
我run了一下你的程序,else下面的return总报错,改成pass就好了
solomonxian
发表于 2017-4-29 18:26:03
有益 发表于 2017-4-29 08:19
我run了一下你的程序,else下面的return总报错,改成pass就好了
因为我原本是写在函数里面的,这里直接复制过来了··· ···
在函数外用 return 会报错{:10_275:}
技术部-李宁
发表于 2017-5-2 16:20:40
#coding: gbk
res = set()
numList = ['1', '2', '3', '4']
for i in numList:
for j in numList:
for k in numList:
if i != j and j != k and k!= i:
res.add(''.join())
print(res)
王志鹏
发表于 2017-5-18 19:23:41
for i in range(1,5):
for j in range(1,5):
for k in range(1,5):
if i != k and i != j and j != k:
print(i,j,k)
渡漫
发表于 2017-5-21 18:08:02
count=0
for i in range(1,5):
for j in range(1,5):
if j!=i:
for k in range(1,5):
if k!=j and k!=i:
print(i,j,k,sep='')
count+=1
print('总共{0}个'.format(count))
假装自己是大佬
新手·ing
发表于 2017-5-21 19:54:29
渡漫 发表于 2017-5-21 18:08
假装自己是大佬
{:10_262:}小家伙你好棒
渡漫
发表于 2017-5-21 21:38:12
新手·ing 发表于 2017-5-21 19:54
小家伙你好棒
{:10_282:}活抓大佬
NwkerWang
发表于 2017-5-25 11:12:54
n = 0
a = 4
b = 4
c = 4
while a:
while b:
while c:
if (a!=b) and (b!=c) and (a!=c):
print (a,b,c)
n += 1
c -= 1
b -= 1
c = 4
a -= 1
b = 4
print ("总数是",n)
好像不太简洁的样子
抑痒指
发表于 2017-6-1 11:01:47
#方法1-----------不知道那个什么 for a in range(1,5):的时候用笨的方法
a=1
Num=0
while a<5:
b=1
while b<5:
c=1
while c<5:
if a!=b and b!=c and a!=c:
print(a,b,c)
Num = Num+1
c=c+1
b=b+1
a=a+1
print('共有%d个数字'%Num)
#方法2------------知道for a in range(1,5)时的小改进,我觉得可以减少一点计算机的工作量
for a in range(1,5):
for b in range(1,5):
if a != b:
for c in range (1,5):
if c !=a and c != b:
print(a,b,c)
Richardliu
发表于 2017-6-12 15:00:08
num = 0
count = 0
for hundred in (1,2,3,4):
for ten in (1,2,3,4):
for base in (1,2,3,4):
if hundred != ten and hundred != base and ten != base:
num = 100*hundred + 10*ten + base
print(num)
count = count + 1
print('total %d numbers!\n' %count)
请各位高手多多指教
Teagle
发表于 2017-6-19 22:24:30
from itertools import combinations
n = range(1,5)
print(list(combinations(n,3)))
print(len(list(combinations(n,3))))
{:5_91:}{:5_91:}
[(1, 2, 3), (1, 2, 4), (1, 3, 4), (2, 3, 4)]
4
Teagle
发表于 2017-6-19 22:29:27
Teagle 发表于 2017-6-19 22:24
看错题目了{:5_104:}{:5_104:}
from itertools import permutations
n = range(1,5)
print(list(permutations(n,3)))
print(len(list(permutations(n,3))))
[(1, 2, 3), (1, 2, 4), (1, 3, 2), (1, 3, 4), (1, 4, 2), (1, 4, 3), (2, 1, 3), (2, 1, 4), (2, 3, 1), (2, 3, 4), (2, 4, 1), (2, 4, 3), (3, 1, 2), (3, 1, 4), (3, 2, 1), (3, 2, 4), (3, 4, 1), (3, 4, 2), (4, 1, 2), (4, 1, 3), (4, 2, 1), (4, 2, 3), (4, 3, 1), (4, 3, 2)]
24
登上南极的熊
发表于 2017-6-27 12:27:41
for i in range(1,5):
for j in range(1,5):
for k in range(1,5):
if i != k and i != j and j != k:
print(i,j,k)
776667
发表于 2017-7-14 10:41:22
from itertools import permutations
print(list(permutations(,3)))
bozhen
发表于 2017-8-11 17:09:21
本帖最后由 bozhen 于 2017-8-11 17:15 编辑
for a in range(1,5):
for b in range(1,5):
for c in range(1,5):
if a != b and a != c and b!=c:
print(a,b,c)
小山90
发表于 2017-8-16 18:22:57
print("--------1、2、3、4,能组成多少个互不相同且无重复数字的三位数-------")
flag = 0
for i in range(1,5):
for j in range(1,5):
for k in range(1,5):
if i!=j and i!=k and j!=k:
print(100*i+10*j+k)
flag += 1
print("共有组合:")
print(flag)
--------1、2、3、4,能组成多少个互不相同且无重复数字的三位数-------
123
124
132
134
142
143
213
214
231
234
241
243
312
314
321
324
341
342
412
413
421
423
431
432
共有组合:
24
页:
1
[2]
3
4
5
6
7
8
9
10
11