- Code: Select all

"""This program is a simple coin flipper that shows what whether you got

heads or tails and asks if you want to flip again.

"""

#Coin.py

import random

class coin:

def __init__(self):

heads = 0

tails = 0

def flip(self):

result = random.randint(0,1)

if result == 0:

print("Heads")

elif result == 1:

print("Tails")

def main():

print("This is a coin flipper program.")

input("To start press ENTER:")

coin1 = coin()

def flipCoin():

coin1.flip()

answer = input("Do you want to flip again?(y/n):")

if answer == "y":

flipCoin()

elif answer == "n":

print("Ok, Goodbye")

flipCoin()

main()

I've also made another version of this program that tracks results of all coin flips but I'm having trouble with the tracker as the values always stay at zero.

- Code: Select all
`"""This program is a simple coin flipper that shows what whether you got`

heads or tails and asks if you want to flip again.

"""

### Version 1.1

### This version now keeps track of all results.

#Coin_1.1.py

import random

class coin:

def __init__(self):

heads = 0

tails = 0

def flip(self):

result = random.randint(0,1)

if result == 0:

print("Heads")

heads =+ 1

elif result == 1:

print("Tails")

tails =+ 1

print("Heads:", heads,"Tails:",tails)

def main():

print("This is a coin flipper program.")

input("To start press ENTER:")

coin1 = coin()

def flipCoin():

coin1.flip()

answer = input("Do you want to flip again?(y/n):")

if answer == "y":

flipCoin()

elif answer == "n":

print("Ok, Goodbye")

flipCoin()

main()