r/funny • • Jun 09 '12

Pidgonacci Sequence

Post image

[deleted] — view deleted post

1.5k Upvotes

22k comments sorted by

View all comments

Show parent comment

1

u/the_skeptic Jun 10 '12

Terminal comes with Python!

  • Open Terminal.
  • Copy the code below into a file named fibonacci.py and save in a folder of your choice.
  • Naivgate to that folder in the Terminal and run the command python fibonacci.py.
  • Voilá!

      a = 0
    
      b = 1
    
      temp = 0
    
      counter = 1
    
      res = 'y'
      
      goTo = input("Give the number you want to skip to: ")
      
      print("fib(1) = 1")
    
      while counter < goTo or res != 'n':
          if counter >= goTo:
              res = raw_input("Continue? (y/n): ")
          temp = a
          a = b
          b = a + temp
          counter += 1
          print 'F({0}) =\n{1}\n'.format(counter,b)

1

u/Therianthrope Jun 10 '12

"unexpected character after line continuation character" Why do I always get this error?

1

u/the_skeptic Jun 10 '12

I don't know. It works by a simple copy-paste when I try. Make shure to have all indentation be a mutiple of four white spaces, that is, there should be four spaces before "if" and all lines below, except for the "res = ..." line which should have 8 spaces in front.

Does it give any indication as to which line gives the error?