dimanche 9 août 2020

Made a function but it ignores my optional True/False statement

So, I was just making a fibonacci function to return a printed version of the sequence and the variation, but it seems to be ignoring the 'if' statement and jumping to the "else". Don't have a clue of what could be happening here...

def fibonacci(r, var=False):
if var is True:
    n1 = 0
    n2 = 1
    for c in range(0, r):
        n3 = n1 + n2
        v = n3 / n2
        n1 = n2
        n2 = n3
        print(f'{v}', end=' ')
else:
    n1 = -1
    n2 = 1
    for c in range(0, r):
        n3 = n1 + n2
        n1 = n2
        n2 = n3
        print(f'{n3}', end=' ')


fibonacci((20, True))

Aucun commentaire:

Enregistrer un commentaire