1,105,578 Community Members

branching,while loops,and program planning

Member Avatar
marethamogale
Newbie Poster
6 posts since Sep 2013
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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

Member Avatar
Gribouillis
Posting Maven
3,456 posts since Jul 2008
Reputation Points: 1,140 [?]
Q&As Helped to Solve: 884 [?]
Skill Endorsements: 18 [?]
Moderator
 
0
 

Where are your efforts to solve the assignment ?

Member Avatar
vegaseat
DaniWeb's Hypocrite
6,984 posts since Oct 2004
Reputation Points: 1,544 [?]
Q&As Helped to Solve: 1,872 [?]
Skill Endorsements: 67 [?]
Moderator
 
0
 

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

Member Avatar
marethamogale
Newbie Poster
6 posts since Sep 2013
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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)

Member Avatar
slate
Posting Whiz
375 posts since Jun 2008
Reputation Points: 163 [?]
Q&As Helped to Solve: 107 [?]
Skill Endorsements: 10 [?]
 
0
 

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.

Member Avatar
phorce
Veteran Poster
1,016 posts since Jul 2011
Reputation Points: 119 [?]
Q&As Helped to Solve: 133 [?]
Skill Endorsements: 29 [?]
Featured
 
0
 

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. :)

Question Answered as of 6 Months Ago by vegaseat, slate, Gribouillis and 1 other
You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article