python实现四个数能随机组成多少个不同的三位数

m_list = list(input("请输入四个数:"))
print(m_list)
c = 0
# 数字范围0 - 9
while c < 4:
    if int(m_list[c])//10 != 0:
        print("输入数字不合法")
        break
    c += 1
else:
    print("数字都合法")
    # 穷举可能性
    count = 0  # 计数器

    for i in range(len(m_list)):
        for j in range(len(m_list)):
            for k in range(len(m_list)):
                if m_list[i] != m_list[j] and m_list[i] != m_list[k] and m_list[j] != m_list[k]:
                    # 存在有个0的情况
                    if m_list[i] == "0":
                        continue
                    else:
                        print(m_list[i], m_list[j], m_list[k], end="   ")
                    	count += 1
    print("\n一共{}个".format(count))
发布了221 篇原创文章 · 获赞 113 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/qq_42363032/article/details/104454928