思路:
三位数有个位,十位,百位 ,要想不漏掉,我们可以用for循环去遍历个位、十位和百位。
步骤:
1.我们先把每一位都遍历并且组合,就可以得到所有的三位数。
2.我们再把重复的给去掉。(用几个if 去判断,筛选出重复的部分)
for bai in range(1, 5):
for shi in range(1, 5):
for ge in range(1, 5):
if (ge != shi) and (ge != bai) and (shi != bai): # if 筛选出有重复的三位数
num = bai*100 + shi*10 + ge
print(f'{num}', end=' | ') # 这里用 f 格式化输出
print()
结果为: