[Tutor] While Loops: Coin Flip Game :p:

Nithya Nisha nithyakarpagam at gmail.com
Tue Nov 16 13:41:10 CET 2010


Thankyou..!!!


Regards,
Nithya

On Tue, Nov 16, 2010 at 1:51 PM, Luke Pettit <petluke at gmail.com> wrote:

> Arrr thats better Nithya it works fine now. I had it working fine before
> it was just coming up with that strange result of 73 and 100
> when I copied the code into wing to check it out in order to understand it.
> Wing picked up the spacing and I had already corrected
> that Dave as I was simply looking at Nithya code.
>
>
> On 16 November 2010 19:10, Nithya Nisha <nithyakarpagam at gmail.com> wrote:
>
>> Hi there,
>>
>> This is the Code. Please check it.It is working fine.
>>
>> >>>import random
>> >>>headsCount = 0
>> >>>tailsCount = 0
>> >>>count = 1
>> >>>
>> >>>while count <= 100:
>> >>>       coin = random.randrange(2)
>> >>>       if coin == 0:
>> >>>             headsCount += 1
>> >>>       else:
>> >>>             tailsCount += 1
>> >>>       count += 1
>> >>>
>> >>>print "The number of heads was", headsCount
>> >>>print "The number of tails was", tailsCount
>> >>>
>> >>>raw_input("\n\nPress the enter key to exit.")
>>
>>
>> ________________________________________________________________________________________________________________
>> *
>> Your Description *:
>>
>> On Tue, Nov 16, 2010 at 1:25 PM, Dave Angel <davea at ieee.org> wrote:
>>
>>>  When I run this code (I'm also a noob) I get this result:-
>>>>
>>>>  [evaluate lines 1-22 from untitled-1.py]
>>>>>>>
>>>>>> The number of heads was 73
>>>> The number of tails was 100
>>>>
>>>> Press the enter key to exit.
>>>>
>>>> # Surely, if flipping a single coin 100 times your total number of heads
>>>> and
>>>> tails should add up to 100
>>>> # not 173 or am I missing the point?
>>>>
>>>>
>>>>  No, you're missing an indentation.  If you check the code you're
>>> running, I think you'll find that you didn't unindent the line incrementing
>>> count.
>>>
>>> Of course, it's less error prone to simply use
>>> for count in xrange(100):
>>>
>>> instead of while count < 100:
>>>
>>> and you wouldn't need to increment count.
>>>
>>> DaveA
>>>
>>>
>>
>>
>> --
>> With Regards,
>> Nithya S
>>
>>
>
>
> --
> Luke Pettit
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20101116/dc4a77a9/attachment.html>


More information about the Tutor mailing list