[Tutor] beginner here
Max S.
maxskywalker1 at gmail.com
Thu Dec 8 02:39:06 CET 2011
You are using an 'elif' for your 'coin_rolls == 1:'. The 'elif' keyword
means that if the last 'if' statement (and any 'elif's behind it) was *not*
true, only then will it be executed. Your code could be written as 'if
rolls is NOT less than or equal to 100, only then check to see if it is 1
or 2'. Replace your first 'elif' with 'if', and it should work.
On Wed, Dec 7, 2011 at 8:17 PM, Do youknow who <mrsannman at yahoo.com> wrote:
> Im trying to write this program where i make it flip a coin 100 times then
> tells me the number of heads and tails it came up with.
>
> this is what I got but it does not run
>
> # Coin Flip
> # Demonstrating the While loop
> import random
> print("I will flip a coin 100 times and tell you")
> print(", how many heads and how many tails I got.")
> coin_rolls = random.randint(1,2)
> heads = 0
> tails = 0
> rolls = 0
>
> if rolls <= 100:
> rolls += 1
>
> elif coin_rolls == 1:
> heads += 1
> elif coin_rolls == 2:
> tails += 1
> else:
> print("error")
> print("There was ", heads, "rolls for heads,")
> print("\nand there was ", tails, " rolls for tails.")
> input("\n\nPress the enter key to exit.")
>
> I end up with 0 rolls for heads and 0 rolls for tails...I have made
> attempts to put the
> "coin_rolls = random.randint(1,2)" within the loops but only end up with
> errors
> what wrong with my code?
>
> _______________________________________________
> 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/20111207/5a4127bd/attachment.html>
More information about the Tutor
mailing list