Start New Discussion within our Software Development Community

write a program that stimulates flipping a coin 100 times and then displays the total number of heads and total number of tails achieved

score=raw_input("enter your score:") if score=random.randrange(999)+1 print "nothing to brag about" raw_input(\n\nPress the enter key to exit)

Your code has hardly anything to do with the task you mentioned in the first post.

Try to program the following procedure in python.

Let's make two variable that will store the number of tails and heads.
Let they be: numtails=0, numheads=0
Loop begins here. Count 100 times.
For each count generate a coin flip, head or tail.
If the coin is head, increase numheads, else increase numtails by one.
Loop ends here.
Print out numheads and numtails.

Because I'm learning Python at the moment, I'm going to give you a start.. Something like this:

import string
import random 

def FlipCoin(): 

    coin = ['heads', 'tails'];

    return random.choice(coin);

def main():

    heads = 0;
    tails = 0;

    for x in range(0, 100):
        print FlipCoin();


I'm sure that you can finish this off. :)

This question has already been answered. Start a new discussion instead.