Programming, website development forum Get latest updates by RSS Follow TechnicalTalk on Twitter Follow TechnicalTalk on Facebook 
HomeSearchRecent PostsLoginRegisterContact Us

Username  
Password    
  Forgot your password?  

Pages: [1]   Go Down
 
  Email this topic  |  Print
0 Members and 1 Guest are viewing this topic.

program for fibonnaci number in python

 
webmaster forum
raj  Offline
Activity
0%
 
New Coder
Posts: 25
Topics: 14
January 25, 2009, 02:24:38 AM

I was trying to write a program for Fibonacci as is described on wikipedia and the problem that I am facing is that no matter how big I keep the limit it says to be overflowing.
I have tried keeping it unlimited but still the same problem arises.
 
webmaster forum
polas  Offline
Activity
33.33%
 
Code Guru
Gender: Male
Posts: 1399
Topics: 85
WWW
January 25, 2009, 01:23:29 PM

Post the python code here, I don't know python but might be able to figure out what has gone wrong

Mesham Type Oriented Parallel Programming Language, Free online technical support
 
webmaster forum
singam  Offline
Activity
0%
 
Regular Coder
Posts: 50
Topics: 19
July 02, 2010, 08:31:08 PM

Although the recursive implementation given above is elegant and close to the mathematical definition, it is not very practical. Calculating the nth fibonacci number requires calculating two smaller fibonacci numbers, which in turn require two additional recursive calls each, and so on until all branches reach 1. The iterative solution is faster, but still repeats a lot of calculations when computing successive fibonacci numbers. To remedy this, we can employ memoization to cache previous computations.

We first establish a memoization "cache", which stores previously computed fibonacci numbers. In this case we use an ArrayList, initialized with the first two fibonacci numbers, as the cache. Note that we have also moved from using ints to using Java's BigInteger class, which provides arbitrary-precision integers. As a result, the memoized implementation can also compute much larger fibonacci numbers than the previous solutions (although they too could have been implemented using BigIntegers.
===============
Ben 10 Games


 
webmaster forum
Admin  Offline
*
 
Code Guru
Location: India
Gender: Male
Posts: 1387
Topics: 105
NaviBuster NaviBuster
WWW
July 03, 2010, 07:08:02 AM

@singam: Thank you for the post.
 
webmaster forum
Corrinla  Offline
Activity
0%
 
New Coder
Posts: 28
Topics: 0
December 07, 2010, 07:17:31 PM

thanks for the good article

pandora jewelry | wholesale
 
webmaster forum
sd3189541  Offline
Activity
0%
 
New Coder
Posts: 44
Topics: 0
March 23, 2011, 11:01:23 PM

How to code in python and what are the main rules for coding in python?
 
webmaster forum
Activity
0%
 
New Poster
Posts: 2
Topics: 1
April 05, 2011, 04:30:16 AM

Quote from: raj link=topic=925. msg3808#msg3808 date=1232875478
I was trying to write a program for Fibonacci as is described on wikipedia and the problem that I am facing is that no matter how big I keep the limit it says to be overflowing.  
I have tried keeping it unlimited but still the same problem arises.

def main():
print "This program will compute nth Fibonacci"
print "number where n is a value input by the user. "

x = input("Enter the nth Fibonacci number: ")
s = 1

for i in range(x):
s = s + x

s = s + 1

print "The result is:", s

main()

Dynamicdreamz. com/adobe_business_catalyst_development
 
webmaster forum
Activity
0%
 
Skilled Coder
Posts: 125
Topics: 0
June 03, 2011, 01:22:01 AM

How to code in python and what are the main rules for coding in python?


I have never do programing in python, but i read some rule of Python in a book. I would like to share some rule of python, which are given below.

- Never mix tabs and spaces.
- Limit all lines to a maximum of 79 characters.
- Separate top-level function and class definitions with two blank lines.

Network Management Service
 
webmaster forum
cashcars  Offline
Activity
100%
 
Regular Coder
Posts: 71
Topics: 4
WWW
February 02, 2012, 10:58:49 AM

Code:
Preliminary tip: encase your code in [ code="Python ] and
tags (no spaces on the first tag) so that it'll look pretty.


This is a classic case of recursion:

fib(n) = fib(n-1) + fib(n-2)

The best way to compute it is therefore recursively:

Python Syntax (Toggle Plain Text)

    >>> def fib(n):
    if n <= 0:
    return 0
    elif n == 1:
    return 1
    else:
    return fib(n-1) + fib(n-2)


electrician perth
 
  Email this topic  |  Print
Pages: [1]   Go Up
 
Jump to:  



Powered by SMF 1.1.15 | SMF © 2011, Simple Machines


Google visited last this page February 04, 2012, 08:11:05 PM