Question about Fibonacci sequence generator - nothing prints












1















I was given an assigmnent in my class where I need to write an algorithm that can generate "n" numbers of the Fibonacci sequence.
I feel like this code should work, but am still having troubles locating what bug is preventing it from working.
The algorithm should start printing the Fibonacci sequence starting at the number 2 (the first 3 numbers are patched in), but it only prints the first 3 numbers and my algorithm doesn't print anything.
I even have sophisticated error checking that should rule out bad values, but it isn't reporting anything either.



#/usr/bin/python

import re
import math
import time
import sys

def errchk(hwmny,int1,int2,int3,int4,errcnt):
#Sanity check; first 12 numbers don't have 6's
expression = re.compile(r"^[^6]{1,3}", re.I | re.S) #expression for no sixes
if expression.match(str(int3)): # if it doesn't match
return # return
else: #otherwise
if (hwmny > 12): # as long as it's less than 12
return # no errors
zints.err() #but ifnot, errors
return None

def nofloats():
return math.floor(zints.int3)

class zeroints:
int3=int4 = 0 #int3 and int4 are 0
errcnt = 0 #count the number of errors
def err(self):
print "Errors"
return

hwmny =15 #hwmny variable is 10
int1 =int2 =1 #int1 and int2 are 1
zints = zeroints() #ints init'd to 0
print "0n1n1"

def loop(hwmny,int1,int2,int3,int4,errcnt):
while(((zints.int4<hwmny)or not(zints.int4>0))and not(zints.int4==0)): #while int4 is less than hwmny and error checking
zints.int3 =int1+ int2 #int3 is int1 plus int2
int1 =int2 #int1 is int2
string = 'The Values Are' #string is set to 'The Values Are'
int2= zints.int3 #int2 is int3
errchk(hwmny,int1,int2,zints.int3,zints.int4,zints.errcnt)
print zints.int3 #print int3
zints.int4= zints.int4+1 #int4 is int4 plus 1
loop(hwmny,int1,int2,zints.int3,zints.int4,zints.errcnt)
continue

loop(hwmny,int1,int2,zints.int3,zints.int4,zints.errcnt)









share|improve this question





























    1















    I was given an assigmnent in my class where I need to write an algorithm that can generate "n" numbers of the Fibonacci sequence.
    I feel like this code should work, but am still having troubles locating what bug is preventing it from working.
    The algorithm should start printing the Fibonacci sequence starting at the number 2 (the first 3 numbers are patched in), but it only prints the first 3 numbers and my algorithm doesn't print anything.
    I even have sophisticated error checking that should rule out bad values, but it isn't reporting anything either.



    #/usr/bin/python

    import re
    import math
    import time
    import sys

    def errchk(hwmny,int1,int2,int3,int4,errcnt):
    #Sanity check; first 12 numbers don't have 6's
    expression = re.compile(r"^[^6]{1,3}", re.I | re.S) #expression for no sixes
    if expression.match(str(int3)): # if it doesn't match
    return # return
    else: #otherwise
    if (hwmny > 12): # as long as it's less than 12
    return # no errors
    zints.err() #but ifnot, errors
    return None

    def nofloats():
    return math.floor(zints.int3)

    class zeroints:
    int3=int4 = 0 #int3 and int4 are 0
    errcnt = 0 #count the number of errors
    def err(self):
    print "Errors"
    return

    hwmny =15 #hwmny variable is 10
    int1 =int2 =1 #int1 and int2 are 1
    zints = zeroints() #ints init'd to 0
    print "0n1n1"

    def loop(hwmny,int1,int2,int3,int4,errcnt):
    while(((zints.int4<hwmny)or not(zints.int4>0))and not(zints.int4==0)): #while int4 is less than hwmny and error checking
    zints.int3 =int1+ int2 #int3 is int1 plus int2
    int1 =int2 #int1 is int2
    string = 'The Values Are' #string is set to 'The Values Are'
    int2= zints.int3 #int2 is int3
    errchk(hwmny,int1,int2,zints.int3,zints.int4,zints.errcnt)
    print zints.int3 #print int3
    zints.int4= zints.int4+1 #int4 is int4 plus 1
    loop(hwmny,int1,int2,zints.int3,zints.int4,zints.errcnt)
    continue

    loop(hwmny,int1,int2,zints.int3,zints.int4,zints.errcnt)









    share|improve this question



























      1












      1








      1








      I was given an assigmnent in my class where I need to write an algorithm that can generate "n" numbers of the Fibonacci sequence.
      I feel like this code should work, but am still having troubles locating what bug is preventing it from working.
      The algorithm should start printing the Fibonacci sequence starting at the number 2 (the first 3 numbers are patched in), but it only prints the first 3 numbers and my algorithm doesn't print anything.
      I even have sophisticated error checking that should rule out bad values, but it isn't reporting anything either.



      #/usr/bin/python

      import re
      import math
      import time
      import sys

      def errchk(hwmny,int1,int2,int3,int4,errcnt):
      #Sanity check; first 12 numbers don't have 6's
      expression = re.compile(r"^[^6]{1,3}", re.I | re.S) #expression for no sixes
      if expression.match(str(int3)): # if it doesn't match
      return # return
      else: #otherwise
      if (hwmny > 12): # as long as it's less than 12
      return # no errors
      zints.err() #but ifnot, errors
      return None

      def nofloats():
      return math.floor(zints.int3)

      class zeroints:
      int3=int4 = 0 #int3 and int4 are 0
      errcnt = 0 #count the number of errors
      def err(self):
      print "Errors"
      return

      hwmny =15 #hwmny variable is 10
      int1 =int2 =1 #int1 and int2 are 1
      zints = zeroints() #ints init'd to 0
      print "0n1n1"

      def loop(hwmny,int1,int2,int3,int4,errcnt):
      while(((zints.int4<hwmny)or not(zints.int4>0))and not(zints.int4==0)): #while int4 is less than hwmny and error checking
      zints.int3 =int1+ int2 #int3 is int1 plus int2
      int1 =int2 #int1 is int2
      string = 'The Values Are' #string is set to 'The Values Are'
      int2= zints.int3 #int2 is int3
      errchk(hwmny,int1,int2,zints.int3,zints.int4,zints.errcnt)
      print zints.int3 #print int3
      zints.int4= zints.int4+1 #int4 is int4 plus 1
      loop(hwmny,int1,int2,zints.int3,zints.int4,zints.errcnt)
      continue

      loop(hwmny,int1,int2,zints.int3,zints.int4,zints.errcnt)









      share|improve this question
















      I was given an assigmnent in my class where I need to write an algorithm that can generate "n" numbers of the Fibonacci sequence.
      I feel like this code should work, but am still having troubles locating what bug is preventing it from working.
      The algorithm should start printing the Fibonacci sequence starting at the number 2 (the first 3 numbers are patched in), but it only prints the first 3 numbers and my algorithm doesn't print anything.
      I even have sophisticated error checking that should rule out bad values, but it isn't reporting anything either.



      #/usr/bin/python

      import re
      import math
      import time
      import sys

      def errchk(hwmny,int1,int2,int3,int4,errcnt):
      #Sanity check; first 12 numbers don't have 6's
      expression = re.compile(r"^[^6]{1,3}", re.I | re.S) #expression for no sixes
      if expression.match(str(int3)): # if it doesn't match
      return # return
      else: #otherwise
      if (hwmny > 12): # as long as it's less than 12
      return # no errors
      zints.err() #but ifnot, errors
      return None

      def nofloats():
      return math.floor(zints.int3)

      class zeroints:
      int3=int4 = 0 #int3 and int4 are 0
      errcnt = 0 #count the number of errors
      def err(self):
      print "Errors"
      return

      hwmny =15 #hwmny variable is 10
      int1 =int2 =1 #int1 and int2 are 1
      zints = zeroints() #ints init'd to 0
      print "0n1n1"

      def loop(hwmny,int1,int2,int3,int4,errcnt):
      while(((zints.int4<hwmny)or not(zints.int4>0))and not(zints.int4==0)): #while int4 is less than hwmny and error checking
      zints.int3 =int1+ int2 #int3 is int1 plus int2
      int1 =int2 #int1 is int2
      string = 'The Values Are' #string is set to 'The Values Are'
      int2= zints.int3 #int2 is int3
      errchk(hwmny,int1,int2,zints.int3,zints.int4,zints.errcnt)
      print zints.int3 #print int3
      zints.int4= zints.int4+1 #int4 is int4 plus 1
      loop(hwmny,int1,int2,zints.int3,zints.int4,zints.errcnt)
      continue

      loop(hwmny,int1,int2,zints.int3,zints.int4,zints.errcnt)






      python fibonacci






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 21 '18 at 23:50









      martineau

      67.9k1090183




      67.9k1090183










      asked Nov 21 '18 at 23:42









      XlogicXXlogicX

      399210




      399210
























          1 Answer
          1






          active

          oldest

          votes


















          2














          This fix looks simple.
          The grouping in the while loop is wrong, change it to the following and it should work fine:



          while((zints.int4<hwmny)or not(zints.int4>0)and not(zints.int4==0)):





          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%2f53421986%2fquestion-about-fibonacci-sequence-generator-nothing-prints%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









            2














            This fix looks simple.
            The grouping in the while loop is wrong, change it to the following and it should work fine:



            while((zints.int4<hwmny)or not(zints.int4>0)and not(zints.int4==0)):





            share|improve this answer






























              2














              This fix looks simple.
              The grouping in the while loop is wrong, change it to the following and it should work fine:



              while((zints.int4<hwmny)or not(zints.int4>0)and not(zints.int4==0)):





              share|improve this answer




























                2












                2








                2







                This fix looks simple.
                The grouping in the while loop is wrong, change it to the following and it should work fine:



                while((zints.int4<hwmny)or not(zints.int4>0)and not(zints.int4==0)):





                share|improve this answer















                This fix looks simple.
                The grouping in the while loop is wrong, change it to the following and it should work fine:



                while((zints.int4<hwmny)or not(zints.int4>0)and not(zints.int4==0)):






                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Nov 22 '18 at 1:10









                Supa Mega Ducky Momo da Waffle

                1




                1










                answered Nov 21 '18 at 23:44









                happyhamsturrhappyhamsturr

                362




                362
































                    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%2f53421986%2fquestion-about-fibonacci-sequence-generator-nothing-prints%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

                    MongoDB - Not Authorized To Execute Command

                    Npm cannot find a required file even through it is in the searched directory

                    in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith