1 2 3 4

python习题:三位数的排列

编写一个程序来找出给定数字的排列。

三位数的排列是指三个不同数字的所有可能的排列。例如,数字5,6和7的排列:

567
576
657
675
756
765

代码:

from itertools import permutations

def get_all_permutations(digits):
    # 生成所有可能的排列
    perms = permutations(digits)
    
    # 遍历每个排列并打印出来
    for perm in perms:
        print(perm)

# 示例用法
digits = list(map(int, input().split()))  # 获取整数输入并转换为列表
get_all_permutations(digits)  # 调用函数

运用了 permutations函数

posted @   姑洗初柒  阅读(41)  评论(0编辑  收藏  举报
(评论功能已被禁用)
相关博文:
阅读排行:
· DeepSeek “源神”启动!「GitHub 热点速览」
· 我与微信审核的“相爱相杀”看个人小程序副业
· 微软正式发布.NET 10 Preview 1:开启下一代开发框架新篇章
· C# 集成 DeepSeek 模型实现 AI 私有化(本地部署与 API 调用教程)
· spring官宣接入deepseek,真的太香了~
点击右上角即可分享
微信分享提示