Python's novice question... Fibonacci sequence while statement

Asked 2 years ago, Updated 2 years ago, 101 views

The problem is that when you put the number 10, you'll see a Fibonacci sequence that's less than 10...

What I did was

d = input ("number: ")

def pibo(d):
    a = 0
    b = 1
    c = a + b
    while c < int(d) :
        c = a + b
        a = b
        b = c
        print(c, end = " ")



pibo(d)

When you squeeze it like this

It comes out like this...

Number: 10

1 2 3 5 8 13

But

d = input ("number: ")

def pibo(d):
    a = 0
    b = 1
    c = a + b
    while c < int(d) :
        print(c, end = " ")
        c = a + b
        a = b
        b = c




pibo(d)

Like this, if you lower the print door directly below the while,

Number: 10

1 1 2 3 5 8

What's the difference when it comes out well like this?

python fibonacci

2022-09-22 10:59

1 Answers

There's only one difference.

Is c the output before calculation or the output after calculation.

That's the difference.


2022-09-22 10:59

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.