Python实例002:n个数字能组成多少个互不相同且无重复数字的三位数,分别是多少
n个数字能组成多少个互不相同且无重复数字的三位数,分别是多少
#!/usr/bin/env python3
# -*- coding:utf-8 -*-
List = input('请输入数字组合中的几个不同数字:')
# split('')函数利用分隔符(,/;/空格等)将每个字符进行分隔
List = List.split(',')
# for循环将每个字符转换为int值
for n in range( len(List) ) :
List[n] = int( List[n] )
# List = [int(List[i]) for i in range(len(List))]
print('\n', List, '这',len(List), '个数字组成的互不相同且无重复数字的三位数如下:')
Count = 0
for i in range(len(List)) :
for j in range(len(List)) :
for k in range(len(List)) :
if ( List[i] != List[j] and List[j] != List[k] and List[k] != List[i]) :
print('%d%d%d' % (List[i],List[j],List[k]), end=' ')
Count = Count + 1
# 分行打印,每10个组合数分一行
if (Count % 10 == 0) :