py 123456789 加 +-*/来组合所有可能的式子利用递归算法

def computer(start,list):
    if len(list):
        for symbol in '+-*/':
            x = start + symbol + str(list[0])
            if (len(x)==17):
                print(x)
            computer(x, list[1:])


start = '1'
end = '23456789'
computer(start, end)

这里会输出所有的式子的情况利用的是递归算法

发布了20 篇原创文章 · 获赞 6 · 访问量 1008

猜你喜欢

转载自blog.csdn.net/zhangyunwei_Blog/article/details/105351524