Jump to content
  • Advertisement
Sign in to follow this  
  • entries
    7
  • comments
    2
  • views
    1425

still tinkering with python

Sign in to follow this  
WinterDragon

563 views

Q: assignment that flips a coin 100 times and gives you the total amount of heads and tails.

A: I started by making it flip a coin 5 times so I could easily watch it working and fix bugs.

I don't think it actually flips the coin exactly 100 times, can you spot the error?

It took me an hour to get it to work:

 

import random
def variables ():
    heads = 0
    tails = 0
    coinCount = 0
    againPlay = "y"
   
def game():
    heads = 0
    tails = 0
    againPlay = "y"
    coinCount = 1
    while coinCount > 0:
        if againPlay != "y":
            print ("you had ", heads, "heads.")
            print (" and ", tails, "tails.")
            end = input ("You're all done now!")
        nmCoin = random.randrange(2)
        if coinCount > 100: againPlay = "n"
        if nmCoin == 1:
           heads = heads + 1
           coinCount = coinCount + 1
        elif nmCoin == 0:
           tails = tails + 1
           coinCount = coinCount + 1
        else:
            print ("you had ", heads, "heads.")
            print (" and ", tails, "tails.")
            end = input ("You're all done now!")
    
variables ()
game ()
 

Sign in to follow this  


0 Comments


Recommended Comments

There are no comments to display.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!