- a, b = b, a+b

- a = b

- b= a+b

This and you:

- b = a+b

- a = b

Not the same order.

While the output is not the same as the results,

That's normal.?

Posted by Donald at February 17, 2016 - 12:38 AM

If you write is the Fibonacci sequence, then the first algorithm is wrong.

Here a should be equal to the "last" B, you first algorithm, a is equal to "the last" b value.

Equivalent to f(0) = 0, f(1) = 1, f(n) = f(n-1)+ f(n-1).

And your second algorithm is correct, f(n) = f(n-1)+ f(n-2)

Here a should be equal to the "last" B, you first algorithm, a is equal to "the last" b value.

Equivalent to f(0) = 0, f(1) = 1, f(n) = f(n-1)+ f(n-1).

And your second algorithm is correct, f(n) = f(n-1)+ f(n-2)

Posted by Borg at December 19, 2016 - 8:31 PM

- b = a+b

- a = b

- The above... I feel that it is equivalent to a = b = a + B

- a, b = b, A+b is equivalent to:

- c = a

- a = b

- b = c + b

Posted by Susan at December 25, 2016 - 8:43 PM

- >>> a = 0

- >>> b = 1

- >>> while b <10:

- ... print b

- ... a = b

- ... b = a+b

- ...

- 1

- 2

- 4

- 8

Posted by Betty at December 28, 2016 - 9:04 PM

Posted from your results, you can see:

And:

As a result, can be called:

Same

? ? ?

Of course, if you want to discuss your:

What is the 1.

The 2 algorithm is wrong

That is another matter.

We need to make sure you:

1 local how, want to achieve what effect, what algorithm

2 and then to discuss, the code you write, is wrong, should be changed

The.

What do you say?

- 1

- 1

- 2

- 4

- 8

And:

- 1

- 2

- 4

- 8

As a result, can be called:

Same

? ? ?

Of course, if you want to discuss your:

What is the 1.

The 2 algorithm is wrong

That is another matter.

We need to make sure you:

1 local how, want to achieve what effect, what algorithm

2 and then to discuss, the code you write, is wrong, should be changed

The.

What do you say?

Posted by Donald at January 01, 2017 - 9:54 PM

- a, b = b, a+b

- Equivalent to

- A = the original B

- B = the original a + original B

- a = b

- b = a + b

- In second, a value changes, in fact, are equal to

- b = b + b

Posted by Borg at January 03, 2017 - 11:59 PM

Feel shy, the result is not the same. Thank you！

The intention was to get Fibonacci series results, thoughtThank you！

The intention was to get Fibonacci series results, thought

- a, b = b, a+b

- And

- a = b

- b = a+b

- Is the same

Posted by Betty at January 09, 2017 - 10:51 PM

Thank you very much！

See in the python documentThe first terms should be used in the original A and the original B phase.

Thank you！

See in the python document

- >>> a, b = 0, 1

- >>> while b <10:

- ... print b

- ... a, b = b, a+b

- ...

- 1

- 1

- 2

- 3

- 5

- 8

- The first line contains composite parameters: variable a and B at the same time is set to 0 and 1. The last line of this is used again, proved that the expressions on the right-hand side of the assignment before the first operation. On the right side of the expression from left to right operation.

Thank you！

Posted by Betty at January 12, 2017 - 10:53 PM

Personally feel that this is the correct explanation, look at the books:

a,b = b,A+b this is a tuple assignment, simply omit the()

Tuple assignment Python will establish a temporary tuple, to store the original value of the variable

a,b = b,A+b this is a tuple assignment, simply omit the()

Tuple assignment Python will establish a temporary tuple, to store the original value of the variable

Posted by Megan at January 13, 2017 - 11:52 PM

How do I feel the first is right?

Started by Betty at February 07, 2016 - 12:28 AM