python每天一练
1.有四个数字:1、2、3、4,能组成多少个互不相同且无重复数字的三位数?各是多少?
sum1 = 0
for i in range(1, 5):
for j in range(1, 5):
for k in range(1, 5):
if i != j and j != k and i != k:
print(i, j, k)
sum1 += 1
print(sum1)
踩雷: and和&表示不同运算.and是与运算,&是位与运算.这题如果要用&的话,需加括号
sum1 = 0
for i in range(1, 5):
for j in range(1, 5):
for k in range(1, 5):
if (i != j) & (j != k) & (i != k):
print(i, j, k)
sum1 += 1
print(sum1)