有1、2、3、4个数字,能组成多少个互不相同且无重复数字的三位数?
步骤:先定一个函数,把数据储存在一个列表,然后传入函数中就行了
代码
def threeDN(a):'''组成多少个互不相同且无重复数字的三位数'''num=0for i1 in a:for i2 in a:for i3 in a:if (i1 != i2)and(i2!=i3)and(i1!=i3):print(i1,i2,i3)num=num+1return num
numbers = [1,2,3,4]
number=threeDN(numbers)
print("共有"+str(number)+"个")
解释
三重for循环遍历列表,用and逻辑运算符表示三者不相同就行了
初学者,有错误请多多指教