humble coin head or tail game script I wrote

Camellia breakfastea at gmail.com
Sat Oct 7 11:21:57 CEST 2006


OK so this is the result after I taking everything I'm teached in this
thread:

<code>
print 'Predict Head or Tail in ten times coin thrown\nJust input \'h\'
or \'t\' please\n'

count = 0
user_input = []

while len(user_input) < 10:
    print '\nNo.', len(user_input)+1, ', h or t?'
    pre_user = raw_input()
    if pre_user not in ['t', 'h']:
        print '\njust enter \'h\' or \'t\' please'
        continue
    user_input.append(pre_user)
    count += 1

correct = 0
import random
ini_guess = random.randrange(2)
list_guess = ['t', 'h']
ini_guess = list_guess[ini_guess]
# generate random initial guess
for item in user_input:
    if item == 'h':
        if ini_guess == item:
            correct += 1
        else:
            ini_guess = 'h'
    if item == 't':
        if ini_guess == item:
            correct += 1
        else:
            ini_guess = 't'

print '\n\nI got', correct, 'out of 10 correct.'

raw_input('press enter to exit')

</code>

Thanks for all the people who helped me:)

Peace
Kelvin




More information about the Python-list mailing list