class Fibonacci:
def fn(num):
if num <= 0:
return 0
if num <= 1:
return 1
else:
Result = fn(num - 1) +fn(num - 2)
return Result
amount = int(input("How many numbers do you want? : "))
i = 1
while i < amount:
FibValue = fn(i)
print(FibValue)
i += 1
Fibonacci()
Here are my errors:
File "C:/Users/Carsten/PycharmProjects/untitled/Lesson13.py", line 30, in <module>
class Fibonacci:
File "C:/Users/Carsten/PycharmProjects/untitled/Lesson13.py", line 45, in Fibonacci
FibValue = fn(i)
File "C:/Users/Carsten/PycharmProjects/untitled/Lesson13.py", line 38, in fn
Result = fn(num - 1) +fn(num - 2)
NameError: name 'fn' is not defined
I'm not quite sure as to why I can run the def Fibonacci: function on its own but as soon as I put it under a class it gives me these errors. I'm still a beginner and have little idea of what these errors mean but even looking them up isn't of much assistance. Any help is appreciated. I realize I can use this as just a standalone function but I'm in the middle of a problem in the youtube series I'm watching to teach myself and I don't want to simply skip ahead in the video and just see the answer to the rest of the problem. Thanks