Oisin M
unread,Feb 15, 2012, 5:25:50 AM2/15/12Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to CoderDojo Dublin
#By Oisin M.
import random
guess = 'h'
toss = 0
answer = 'y'
playerwins = 0
computerwins = 0
while answer == 'y':
guess = raw_input ("Choose [h]eads or [t]ails:")
if guess not in ['t','h']:
print ("Input other than t or h received. Program ending.")
break
toss = random.randint(0,1)
if toss == 0:
toss = 'h'
else:
toss = 't'
if (guess == 't' and toss == 't') or (guess == 'h' and toss ==
'h'):
print ("You win! Guess was " + guess + ". Toss was "
+str(toss) +'.')
playerwins = playerwins + 1
print ("Score: Computer = " + str(computerwins) + ", Player =
" + str(playerwins)+ "\n")
else:
print ("You lose! Your guess was " + guess + ". Toss was " +
str(toss) + '.')
computerwins = computerwins + 1
print ("Score: Computer = " + str(computerwins) + ", Player =
" + str(playerwins)+ "\n")
answer = raw_input('Do you wish to continue y or n? ')
if answer not in ['y','n']:
print ("Input other than t or h received. Program ending.")
break
if answer == 'n':
break
#sys.exit(0)