这道题想了半天,知道用for循环,没想用嵌套的方式。还是参考了别人的答案
#for循环嵌套
total = 0
for units in range(1,5): #个位
for tens in range(1,5): #十位
for hundreds in range(1,5): #百位
if units != tens and tens != hundreds and units != hundreds:
sum = hundreds * 100 + tens * 10 + units
if sum >= 100 and sum <1000:
total+= 1
print("这些数分别是: " ,sum)
print("总共有 %d 个数" % (total))