Skip to main content
deleted 14 characters in body; edited title
Source Link
200_success
  • 145.6k
  • 22
  • 191
  • 481

Nth FibonaciiFibonacci number (Bottom-up with dict)

This is an algorithm that I'm trying to writeI wrote to get the nth fibonaciiFibonacci number using bottom-up dictionary.How How can I make this better/more eficcientefficient?

memo={1:1,2:1}
f=0

def Fib(n):
    for i in range(3,n+1):
        memo[i]=memo[i-1]+memo[i-2]


    f=memo[n]
    print(f)
    return f


Fib(15)

Nth Fibonacii number (Bottom-up with dict)

This is an algorithm that I'm trying to write to get the nth fibonacii number using bottom-up dictionary.How can I make this better/more eficcient?

memo={1:1,2:1}
f=0

def Fib(n):
    for i in range(3,n+1):
        memo[i]=memo[i-1]+memo[i-2]


    f=memo[n]
    print(f)
    return f


Fib(15)

Nth Fibonacci number (Bottom-up with dict)

This is an algorithm that I wrote to get the nth Fibonacci number using bottom-up dictionary. How can I make this better/more efficient?

memo={1:1,2:1}
f=0

def Fib(n):
    for i in range(3,n+1):
        memo[i]=memo[i-1]+memo[i-2]


    f=memo[n]
    print(f)
    return f


Fib(15)
Post Reopened by Martin R, 200_success
edit-code is working now
Source Link
Newbie404
  • 131
  • 1
  • 4

This is an algorithm that I'm trying to write to get the nth fibonacii number using bottom-up dictionary:.How can I make this better/more eficcient?

memo={1:1,2:1}
f=0

def Fib(n):
    for i in range(3,n+1):
        memo[i]=memo[i-1]+memo[i-2]

    
 if n in memo:f=memo[n]
    print(f)
    f=memo[n]
  return 
print(f) 


Fib(15)

This is error I get:

Traceback (most recent call last): File "c:\users*****\documents\visual studio 2015\Projects\HelloPython\HelloPython\HelloPython.py", line 13, in Fib(15) File "c:\users(...)\HelloPython.py", line 9, in Fib f=memo[n] KeyError: 15

When I print(f) inside de Fib Function it doesn´t throw any error... I'm fairly new to the python language, I came from c#... Is using a list better? How so?

This is an algorithm that I'm trying to write to get the nth fibonacii number using bottom-up dictionary:

memo={1:1,2:1}
f=0

def Fib(n):
    for i in range(3,n+1):
        memo[i]=memo[i-1]+memo[i-2]

    if n in memo:
        f=memo[n]
   
print(f)
Fib(15)

This is error I get:

Traceback (most recent call last): File "c:\users*****\documents\visual studio 2015\Projects\HelloPython\HelloPython\HelloPython.py", line 13, in Fib(15) File "c:\users(...)\HelloPython.py", line 9, in Fib f=memo[n] KeyError: 15

When I print(f) inside de Fib Function it doesn´t throw any error... I'm fairly new to the python language, I came from c#... Is using a list better? How so?

This is an algorithm that I'm trying to write to get the nth fibonacii number using bottom-up dictionary.How can I make this better/more eficcient?

memo={1:1,2:1}
f=0

def Fib(n):
    for i in range(3,n+1):
        memo[i]=memo[i-1]+memo[i-2]

 
    f=memo[n]
    print(f)
    return f 


Fib(15)
Post Closed as "Not suitable for this site" by Gareth Rees, Mathieu Guindon
Source Link
Newbie404
  • 131
  • 1
  • 4

Nth Fibonacii number (Bottom-up with dict)

This is an algorithm that I'm trying to write to get the nth fibonacii number using bottom-up dictionary:

memo={1:1,2:1}
f=0

def Fib(n):
    for i in range(3,n+1):
        memo[i]=memo[i-1]+memo[i-2]

    if n in memo:
        f=memo[n]
   
print(f)
Fib(15)

This is error I get:

Traceback (most recent call last): File "c:\users*****\documents\visual studio 2015\Projects\HelloPython\HelloPython\HelloPython.py", line 13, in Fib(15) File "c:\users(...)\HelloPython.py", line 9, in Fib f=memo[n] KeyError: 15

When I print(f) inside de Fib Function it doesn´t throw any error... I'm fairly new to the python language, I came from c#... Is using a list better? How so?