My code.

4 views
Skip to first unread message

Oisin M

unread,
Feb 15, 2012, 5:25:50 AM2/15/12
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)
Reply all
Reply to author
Forward
0 new messages