[Tutor] Issue w/ program: Flip a coin and count heads and tails
Rafael Knuth
rafael.knuth at gmail.com
Fri May 24 13:24:37 CEST 2013
>
> I am writing a program in Python 3.3.0 which flips a coin 10 x times and
> then counts the number of heads and tails. It obviously does something else
> than I intended, and I am wondering what I did wrong:
>
What is that you intended?
Please explain that.
I want that program to flip a coin 10 x times and then count the number of
heads and tails.
That's very much it.
On Fri, May 24, 2013 at 1:08 PM, Asokan Pichai <pasokan at talentsprint.com>wrote:
>
>
> On Fri, May 24, 2013 at 4:31 PM, Rafael Knuth <rafael.knuth at gmail.com>wrote:
>
>> Hello,
>>
>> I am writing a program in Python 3.3.0 which flips a coin 10 x times and
>> then counts the number of heads and tails. It obviously does something else
>> than I intended, and I am wondering what I did wrong:
>>
>
> What is that you intended?
> Please explain that.
>
>>
>> import random
>>
>> print ("""
>>
>> This program flips a coin 10 times.
>>
> Actually this is wrong. The program does something else.
>
>
>>
>> It then counts the number of heads and tails.
>>
>> """)
>>
>> flips = 0
>>
>> heads = 0
>>
>> tails = 0
>>
>> while flips < 10:
>>
>> flips = flips + 1
>>
>> if random.randint(1,2) == 1:
>>
>> heads = heads + 1
>>
>> print("We've got " + str(heads) + " heads here."
>>
>> if random.randint(1,2) == 2:
>>
>> tails = tails + 1
>>
>> print("We've got " + str(tails) + " tails here.")
>>
>
>> This is what I get as output:
>>
>> This program flips a coin 10 times.
>>
>> It then counts the number of heads and tails.
>>
>> We've got 1 tails here.
>>
>> We've got 1 heads here.
>>
>> We've got 2 tails here.
>>
>> We've got 2 heads here.
>>
>> We've got 3 tails here.
>>
>> We've got 3 heads here.
>>
>> We've got 4 tails here.
>>
>> We've got 5 tails here.
>>
>> We've got 4 heads here.
>>
>> We've got 6 tails here.
>>
>> We've got 7 tails here.
>>
>> We've got 5 heads here.
>>
> Is this an actual output??? Did the program stop here at 5 heads and 7
> tails?
>
>
>>
>> Can anyone help?
>>
>> Thank you so much!
>>
>> All the best,
>>
>> Rafael
>>
>
> Asokan Pichai
>
> "Expecting the world to treat you fairly because you are a good person is
> a little like expecting the bull to not attack you because you are a
> vegetarian"
>
> _______________________________________________
> Tutor maillist - Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20130524/91c73a3d/attachment.html>
More information about the Tutor
mailing list