python求和_Python程序查找特殊求和系列的解决方案
                                                            生活随笔
收集整理的這篇文章主要介紹了
                                python求和_Python程序查找特殊求和系列的解决方案
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.                        
                                python求和
We are going to design a special sum series function which has following characteristics:
我們將設(shè)計一個特殊的求和系列函數(shù),該函數(shù)具有以下特征:
f(0) = 0f(1) = 1f(2) = 1f(3) = 0f(x) = f(x-1) + f(x-3)Python solution of the above sum series
上述sum系列的Python解決方案
# function to find the sum of the series def summ(x):if x == 0:return 0if x == 1:return 1if x == 2:return 1if x == 3:return 0else:return summ(x-1) + summ(x-4)# main code if __name__ == '__main__':# finding the sum of the series till given value of xprint("summ(0) :", summ(0))print("summ(1) :", summ(1))print("summ(2) :", summ(2))print("summ(3) :", summ(3))print("summ(10):", summ(10))print("summ(14):", summ(14))Output
輸出量
summ(0) : 0 summ(1) : 1 summ(2) : 1 summ(3) : 0 summ(10): 5 summ(14): 17翻譯自: https://www.includehelp.com/python/find-the-solution-of-a-special-sum-series.aspx
python求和
總結(jié)
以上是生活随笔為你收集整理的python求和_Python程序查找特殊求和系列的解决方案的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。