humble coin head or tail game script I wrote
Camellia
breakfastea at gmail.com
Fri Oct 6 14:05:09 EDT 2006
Hi there this is an easy game which was inspired from my psychology
class.
I'll get 5/10 right prediction of your guess of head and tail at most
time.
If you could copy the code and run it that would be great:)
code:
-----------------------
# Head or Tail
#
# Get a list which contains 10 values from the user
# let them predict Head Or Tail in ten times coin thrown
# and then prdict the list by a fixed rule
list = []
print 'Predict Head or Tail in ten times coin thrown\nJust input \'h\'
or \'t\' please\n'
count = 0
while True:
count += 1
print '\nNo.', count, ', h or t? '
pre_user = raw_input()
while pre_user != 'h' and pre_user != 't':
print '\njust enter \'h\' or \'t\' please'
print '\nNo.', count, ', h or t? '
pre_user = raw_input()
list.append(pre_user)
if count == 10:
break
correct = 0
import random
ini_guess = random.randrange(1)
list_guess = ['t', 'h']
ini_guess = list_guess[ini_guess]
# generate random initial guess
for item in list:
if item == ini_guess:
correct += 1
elif item == 'h':
ini_guess = 't'
elif item == 't':
ini_guess == 'h'
print '\n\nI got', correct, 'out of 10 correct.'
raw_input('press enter to exit')
--------------------------------------------
I know it looks stupid, but it's fun:)
peace
Kelvin
More information about the Python-list
mailing list