Absolute beginner here, trying to make a simple coin toss game to practice the first couple of chapters I've read. I tried to add a score board to the game but the score is constantly stuck at 0 to 0. also any other tips would be appreciated as well. I don't know anyone that programs so I could use the advice.
"""This will be an attempt to create a simple
coin toss game in which the player chooses heads or
tails and a random generator will pick one from a list
of either heads or tails and return whether or not
the player chose correctly. I also hope to
create a scoreboard"""
from random import randint
coin = ['heads' , 'tails']
side = coin[0]
guess = 'heads'
token = int(raw_input('how many games?'))
wins = 0
losses = 0
def getinfo(token):
guess = raw_input('Heads or Tails?')
def flipcoin(guess, side, wins, losses):
side = coin[randint(0,1)]
print 'You Chose: %s' %(guess)
print 'Coin Is: %s' %(side)
if guess == side:
print 'you win'
wins = wins + 1
else:
print 'you lose'
losses = losses + 1
def main(token):
while token > 0:
getinfo(token)
flipcoin(guess, side, wins, losses)
if wins > losses:
print "You are winning %s to %d" %(wins , losses)
elif wins == losses:
print "You are tied %s to %d" %(wins , losses)
else:
print "You are losing %s to %d" %(losses, wins)
token -= 1
print '%d games left' %(token)
print 'wins: %s' %(wins)
print 'losses: %s' %(losses)
main(token)