How to fix tribonacci series function when using generatorsHow to flush output of print function?function default value not definedCalling gen.send() with a new generator in Python 3.3+?Python TypeError: non-empty format string passed to object.__format__ on example 24 from learn python the hard way bookGenerator and list return different resultspython3 send() function in generatorsHow to call multiple functions as arguments inside another function?Setting Dataframe loc result in SQL string - Tuples ErrorPython: queue method wait_for predicate with argumentsHow to create a function which take an iterable and a number “n” as an argument and return tuples with values

London underground zone 1-2 train ticket

Only charge capacitor when button pushed then turn on LED momentarily with capacitor when button released

Does a humanoid possessed by a ghost register as undead to a paladin's Divine Sense?

Can this rough design show the required message?

Why do cheap flights with a layover get more expensive when you split them up into separate flights?

What could prevent players from leaving an island?

Getting Lost in the Caves of Chaos

Our group keeps dying during the Lost Mine of Phandelver campaign. What are we doing wrong?

Repeated! Factorials!

How to switch an 80286 from protected to real mode?

Do some languages mention the top limit of a range first?

Is there a way to prevent the production team from messing up my paper?

Why do dragons like shiny stuff?

Make a living as a math programming freelancer?

What was the role of Commodore-West Germany?

Did silent film actors actually say their lines or did they simply improvise “dialogue” while being filmed?

Why should I "believe in" weak solutions to PDEs?

Based on what criteria do you add/not add icons to labels within a toolbar?

What is the German idiom or expression for when someone is being hypocritical against their own teachings?

Why do proponents of guns oppose gun competency tests?

Could an areostationary satellite help locate asteroids?

A verb for when some rights are not violated?

How do I get the =LEFT function in excel, to also take the number zero as the first number?

The meaning of "scale" in "because diversions scale so easily wealth becomes concentrated"



How to fix tribonacci series function when using generators


How to flush output of print function?function default value not definedCalling gen.send() with a new generator in Python 3.3+?Python TypeError: non-empty format string passed to object.__format__ on example 24 from learn python the hard way bookGenerator and list return different resultspython3 send() function in generatorsHow to call multiple functions as arguments inside another function?Setting Dataframe loc result in SQL string - Tuples ErrorPython: queue method wait_for predicate with argumentsHow to create a function which take an iterable and a number “n” as an argument and return tuples with values






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















Following is my approach to return the n element in Tribonacci series



def tri(n,seq = [1, 1, 1]):
for i in range(n-2):
seq = seq[1:] + [sum(seq)]
return seq[-1]


I get the correct result when passing argument through print().



print(tri(10))


Output : 193



However, when using generator(using repl.it), I get error of can only concatenate tuple (not"list") to tuple



I am using below for generator



def tri_generator(): 
for i in range(1000):
yield (i, (1, 1, 1))
yield (i, (1, 0, 1))
yield (i, (1, 2, 3))


Not sure what I am missing? Any help is appreciated.










share|improve this question
































    0















    Following is my approach to return the n element in Tribonacci series



    def tri(n,seq = [1, 1, 1]):
    for i in range(n-2):
    seq = seq[1:] + [sum(seq)]
    return seq[-1]


    I get the correct result when passing argument through print().



    print(tri(10))


    Output : 193



    However, when using generator(using repl.it), I get error of can only concatenate tuple (not"list") to tuple



    I am using below for generator



    def tri_generator(): 
    for i in range(1000):
    yield (i, (1, 1, 1))
    yield (i, (1, 0, 1))
    yield (i, (1, 2, 3))


    Not sure what I am missing? Any help is appreciated.










    share|improve this question




























      0












      0








      0








      Following is my approach to return the n element in Tribonacci series



      def tri(n,seq = [1, 1, 1]):
      for i in range(n-2):
      seq = seq[1:] + [sum(seq)]
      return seq[-1]


      I get the correct result when passing argument through print().



      print(tri(10))


      Output : 193



      However, when using generator(using repl.it), I get error of can only concatenate tuple (not"list") to tuple



      I am using below for generator



      def tri_generator(): 
      for i in range(1000):
      yield (i, (1, 1, 1))
      yield (i, (1, 0, 1))
      yield (i, (1, 2, 3))


      Not sure what I am missing? Any help is appreciated.










      share|improve this question
















      Following is my approach to return the n element in Tribonacci series



      def tri(n,seq = [1, 1, 1]):
      for i in range(n-2):
      seq = seq[1:] + [sum(seq)]
      return seq[-1]


      I get the correct result when passing argument through print().



      print(tri(10))


      Output : 193



      However, when using generator(using repl.it), I get error of can only concatenate tuple (not"list") to tuple



      I am using below for generator



      def tri_generator(): 
      for i in range(1000):
      yield (i, (1, 1, 1))
      yield (i, (1, 0, 1))
      yield (i, (1, 2, 3))


      Not sure what I am missing? Any help is appreciated.







      python-3.x






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 27 at 3:58







      N997

















      asked Mar 27 at 3:50









      N997N997

      655 bronze badges




      655 bronze badges

























          1 Answer
          1






          active

          oldest

          votes


















          1














          Here's a simple generator (you can clean up the code as you may like):



          def tri_generator():
          i = 0
          seq = [1, 1, 1]
          while True:
          seq = [seq[1], seq[2], seq[0] + seq[1] + seq[2]]
          yield i, seq
          i += 1

          n = 10
          xx = tri_generator()
          for i in range(n - 2):
          print(next(xx))

          ## Output:
          ## (0, [1, 1, 3])
          ## (1, [1, 3, 5])
          ## (2, [3, 5, 9])
          ## (3, [5, 9, 17])
          ## (4, [9, 17, 31])
          ## (5, [17, 31, 57])
          ## (6, [31, 57, 105])
          ## (7, [57, 105, 193])





          share|improve this answer
























            Your Answer






            StackExchange.ifUsing("editor", function ()
            StackExchange.using("externalEditor", function ()
            StackExchange.using("snippets", function ()
            StackExchange.snippets.init();
            );
            );
            , "code-snippets");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "1"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













            draft saved

            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55369515%2fhow-to-fix-tribonacci-series-function-when-using-generators%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            1














            Here's a simple generator (you can clean up the code as you may like):



            def tri_generator():
            i = 0
            seq = [1, 1, 1]
            while True:
            seq = [seq[1], seq[2], seq[0] + seq[1] + seq[2]]
            yield i, seq
            i += 1

            n = 10
            xx = tri_generator()
            for i in range(n - 2):
            print(next(xx))

            ## Output:
            ## (0, [1, 1, 3])
            ## (1, [1, 3, 5])
            ## (2, [3, 5, 9])
            ## (3, [5, 9, 17])
            ## (4, [9, 17, 31])
            ## (5, [17, 31, 57])
            ## (6, [31, 57, 105])
            ## (7, [57, 105, 193])





            share|improve this answer





























              1














              Here's a simple generator (you can clean up the code as you may like):



              def tri_generator():
              i = 0
              seq = [1, 1, 1]
              while True:
              seq = [seq[1], seq[2], seq[0] + seq[1] + seq[2]]
              yield i, seq
              i += 1

              n = 10
              xx = tri_generator()
              for i in range(n - 2):
              print(next(xx))

              ## Output:
              ## (0, [1, 1, 3])
              ## (1, [1, 3, 5])
              ## (2, [3, 5, 9])
              ## (3, [5, 9, 17])
              ## (4, [9, 17, 31])
              ## (5, [17, 31, 57])
              ## (6, [31, 57, 105])
              ## (7, [57, 105, 193])





              share|improve this answer



























                1












                1








                1







                Here's a simple generator (you can clean up the code as you may like):



                def tri_generator():
                i = 0
                seq = [1, 1, 1]
                while True:
                seq = [seq[1], seq[2], seq[0] + seq[1] + seq[2]]
                yield i, seq
                i += 1

                n = 10
                xx = tri_generator()
                for i in range(n - 2):
                print(next(xx))

                ## Output:
                ## (0, [1, 1, 3])
                ## (1, [1, 3, 5])
                ## (2, [3, 5, 9])
                ## (3, [5, 9, 17])
                ## (4, [9, 17, 31])
                ## (5, [17, 31, 57])
                ## (6, [31, 57, 105])
                ## (7, [57, 105, 193])





                share|improve this answer













                Here's a simple generator (you can clean up the code as you may like):



                def tri_generator():
                i = 0
                seq = [1, 1, 1]
                while True:
                seq = [seq[1], seq[2], seq[0] + seq[1] + seq[2]]
                yield i, seq
                i += 1

                n = 10
                xx = tri_generator()
                for i in range(n - 2):
                print(next(xx))

                ## Output:
                ## (0, [1, 1, 3])
                ## (1, [1, 3, 5])
                ## (2, [3, 5, 9])
                ## (3, [5, 9, 17])
                ## (4, [9, 17, 31])
                ## (5, [17, 31, 57])
                ## (6, [31, 57, 105])
                ## (7, [57, 105, 193])






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Mar 27 at 6:12









                SanVSanV

                5391 silver badge11 bronze badges




                5391 silver badge11 bronze badges





















                    Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.







                    Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.



















                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55369515%2fhow-to-fix-tribonacci-series-function-when-using-generators%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

                    용인 삼성생명 블루밍스 목차 통계 역대 감독 선수단 응원단 경기장 같이 보기 외부 링크 둘러보기 메뉴samsungblueminx.comeh선수 명단용인 삼성생명 블루밍스용인 삼성생명 블루밍스ehsamsungblueminx.comeheheheh

                    155 수학 과학 기타 둘러보기 메뉴eh추가해eh문서를 완성해