三位数的各位数字之和是n,各位数字都不为0,各位数字都不相同。如果有这样的三位数,输出个数;如果没有,输出无解。n从键盘输入
用分离函数了但我不知道后面怎么写
# 读入n
n = int(input())
# 初始化计数器
count = 0
# 从100到999循环
for i in range(100, 1000):
# 取出每一位数字
hundreds = i // 100
tens = (i // 10) % 10
units = i % 10
# 判断是否满足条件
if hundreds + tens + units == n and hundreds != 0 and tens != 0 and units != 0 and hundreds != tens and hundreds != units and tens != units:
# 如果满足条件,计数器+1
count += 1
# 判断是否有解
if count > 0:
print(count)
else:
print("无解")