Re: [Tutor] if >= 0

2014-02-14 Thread ALAN GAULD
CCing the list. Please use Reply All when responding.

> thanks Alan, i understand now zero is False. 

That's right. but...

> so if one of the 'if' test is false, that 'for' loop is also halted? 
> and does not proceed to the next element?

This bit  is wrong.


The for loop will continue to completion every time.


>>> for element in in_file:
>>>   if  element.find(LOCUS'):

>>>     locus += element
>>>   elif element.find(...)

What happens is that because the find(LOCUS) is the first test it will almost 
always be true. So the locus += element will be executed on almost every line
Because that branch of the if construct is executed no other branch is executed.

In an if/elif/else structure only one branch ever gets executed in a given 
iteration of the for loop. elif stands for "else if" so the test in the elif 
statements 
only get executed if all the preceding tests fail. So the order of the tests is 
very important. Now in your case the first branch nearly always succeeds  
and so the subsequent branches never get executed. 

When you add the >=0 condition you stop the first test from catching everything.

So the lines that do not contain LOCUS now get tested for the other values 
and as a result update their respective string variables.

But the for loop continues regardless of which branch is used, it is only 
controlled by the number of lines in the file. It does not care what the code 
inside the loop body does (unless it explicitly uses return or break or 
continue).

HTH

Alan g. 
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] can I make a while loop true again

2014-02-14 Thread Peter Otten
Ian D wrote:

> Anyway thanks. I wondered why array was being mentioned ha ha
> So have I got this correct in that when I run a turtle program I am in
> fact using this forever loop, so I do not need to use a while True loop at
> all really in a turtle gui program?

Yes.

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Beginner - explaining 'Flip a coin' bug

2014-02-14 Thread David Hutto
Here is a problem I've come across, from empirical evidence, that also
relates to your equation. We always assume
 that their are always two probabilities, that a coin can be either head or
tails.

However, there are dynamics within a third realm of the dimensionality of
the coin...it's not a two dimensional plane. So the planar probabilities in
relation to the 'surface are' hold another possibility...the 'edge'.

The algorithm of applying the edge are up to you, but I've seen the coin
land on it's curved edge more than once, so this function you've designed,
should have more than two possibilities, within a complete algorithm to the
real world functionality of the coin in question.


On Wed, Feb 12, 2014 at 10:25 AM, Marc Eymard wrote:

> Hello there,
>
> I want to emulate a coin flip and count how many heads and tails when
> flipping it a hundred times.
>
> I first coded *coinflip_WRONG.py* with "count_flips += 1" statement
> within the *if/else* block.
> When running it, either returned values are wrong or the script seems to
> enter in an infinite loop showing no return values at all.
>
> *coinflip.py* is a corrected version I worked out myself. I moved
> "count_flips+= 1" out of *if/else* block and inserted it before* if/else*.
>
> However, I still don't understand the bug since, in my understanding, both
> files are incrementing variable *count_flips* each time until the loop
> becomes false.
>
> Can somebody explain the reason of the bug.
> Cheers,
>
> Marc
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>
>


-- 
Best Regards,
David Hutto
*CEO:* *http://www.hitwebdevelopment.com *
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Beginner - explaining 'Flip a coin' bug

2014-02-14 Thread David Hutto
On Fri, Feb 14, 2014 at 10:49 PM, David Hutto wrote:

> Here is a problem I've come across, from empirical evidence, that also
> relates to your equation. We always assume
>  that their are always two probabilities, that a coin can be either head
> or tails.
>
> However, there are dynamics within a third realm of the dimensionality of
> the coin...it's not a two dimensional plane. So the planar probabilities in
> relation to the 'surface are' *surface area hold another possibility...the
> 'edge'.
>
> The algorithm of applying the edge are up to you, but I've seen the coin
> land on it's curved edge more than once, so this function you've designed,
> should have more than two possibilities, within a complete algorithm to the
> real world functionality of the coin in question.
>
>
> On Wed, Feb 12, 2014 at 10:25 AM, Marc Eymard wrote:
>
>> Hello there,
>>
>> I want to emulate a coin flip and count how many heads and tails when
>> flipping it a hundred times.
>>
>> I first coded *coinflip_WRONG.py* with "count_flips += 1" statement
>> within the *if/else* block.
>> When running it, either returned values are wrong or the script seems to
>> enter in an infinite loop showing no return values at all.
>>
>> *coinflip.py* is a corrected version I worked out myself. I moved
>> "count_flips+= 1" out of *if/else* block and inserted it before* if/else*
>> .
>>
>> However, I still don't understand the bug since, in my understanding,
>> both files are incrementing variable *count_flips* each time until the
>> loop becomes false.
>>
>> Can somebody explain the reason of the bug.
>> Cheers,
>>
>> Marc
>>
>> ___
>> Tutor maillist  -  Tutor@python.org
>> To unsubscribe or change subscription options:
>> https://mail.python.org/mailman/listinfo/tutor
>>
>>
>
>
> --
> Best Regards,
> David Hutto
> *CEO:* *http://www.hitwebdevelopment.com
> *
>



-- 
Best Regards,
David Hutto
*CEO:* *http://www.hitwebdevelopment.com *
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Beginner - explaining 'Flip a coin' bug

2014-02-14 Thread David Hutto
Just to add a footnote to the above remember:

http://en.wikipedia.org/wiki/Random_seed

unless setting your own random seed algorithm is applied.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor