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

Recommended Answers

All 5 Replies

Where are your efforts to solve the assignment ?

Give us the code you have written so far and the problems you had.

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();

main();

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.