Re: [Tutor] Fibonacci Series

2013-11-25 Thread Rafael Knuth
@Alan @Dave @Dominik thank you all so much for the elaborate explanations! It's really simple and crystal clear now, the most difficult part was actually to detect and overcome my own misconceptions. Once I did that, the rest was really easy. Kind of a valuable learning for the future ;-) Instead

[Tutor] Fibonacci Series

2013-11-24 Thread Rafael Knuth
Hej there, I am making a couple wrong assumptions about the program below, but I do not know where my thinking mistake is. I have some trouble understanding what exactly happens within this loop here: a, b = 0, 1 while b 10: print(b) a, b = b, a +b What I would expect as an outcome of

Re: [Tutor] Fibonacci Series

2013-11-24 Thread Dominik George
Hi, a, b = b, a +b a = b = 1 b = a + b = 1 + 1 = 2 Your issue is that you interpret the assignment wrong. You seem to think that it assigns b to a and THEN a+b to b, which is not the case. The right side of the assignment creates a tuple, and the left side unpacks it. It is the same as:

Re: [Tutor] Fibonacci Series

2013-11-24 Thread Dave Angel
On Sun, 24 Nov 2013 11:24:43 +0100, Rafael Knuth rafael.kn...@gmail.com wrote: a, b = b, a +b a = b = 1 b = a + b = 1 + 1 = 2 I suggest you play with the statement a bit. Print out both values each time through the loop. The expression b, a+b produces a tuple. The left side a, b

Re: [Tutor] Fibonacci Series

2013-11-24 Thread Rafael Knuth
Now I got it, thanks :-) a, b = b, b + a ... I was was wrongly assuming that a and b on the left side talk to each other and that a tells b something like: Hey 'b' ... I just assigned another value to you, make sure you execute it. But a and b don't talk to each other. Each of them executes

Re: [Tutor] Fibonacci Series

2013-11-24 Thread Alan Gauld
On 24/11/13 13:05, Rafael Knuth wrote: a and b on the left side are unchangable tuples and they simply get unpacked on the right side. Be careful about terminology here. a,b is a single tuple with two values. But a and b are variables not tuples. Tuples are collections of (one or more)

Re: [Tutor] Fibonacci series(perhaps slightly off topic)

2008-07-03 Thread Emil
] Date: Thu, 3 Jul 2008 12:59:39 +1200 From: [EMAIL PROTECTED] To: [EMAIL PROTECTED] Subject: Re: [Tutor] Fibonacci series(perhaps slightly off topic) CC: tutor@python.org On 03/07/2008, Emil wrote: I have created a class called Fibs which allow you

Re: [Tutor] Fibonacci series(perhaps slightly off topic)

2008-07-03 Thread Mark Tolonen
): self.fibsseq.append(self.fibsseq[-1] + self.fibsseq[-2]) return self.fibsseq[key] Date: Thu, 3 Jul 2008 12:59:39 +1200 From: [EMAIL PROTECTED] To: [EMAIL PROTECTED] Subject: Re: [Tutor] Fibonacci series(perhaps slightly off topic) CC: tutor@python.org On 03/07/2008

[Tutor] Fibonacci series(perhaps slightly off topic)

2008-07-02 Thread Emil
Hello all I have created a class called Fibs which allow you to access a specific number in the Fibonacci series(http://en.wikipedia.org/wiki/Fibonacci_number) But it seems to me that it is a bit inefficient, any suggestions on how to make it more efficient? Here is the code: class

Re: [Tutor] Fibonacci series(perhaps slightly off topic)

2008-07-02 Thread John Fouhy
On 03/07/2008, Emil [EMAIL PROTECTED] wrote: I have created a class called Fibs which allow you to access a specific number in the Fibonacci series(http://en.wikipedia.org/wiki/Fibonacci_number) But it seems to me that it is a bit inefficient, any suggestions on how to make it more