Skip to content

Instantly share code, notes, and snippets.

@kkt-ee
Created January 1, 2020 16:12
Show Gist options
  • Save kkt-ee/02cf71c71dd4cff15e7af46dafaf5b4e to your computer and use it in GitHub Desktop.
Save kkt-ee/02cf71c71dd4cff15e7af46dafaf5b4e to your computer and use it in GitHub Desktop.
A demo coin toss game with random.randint(0,1) where 0,1 => tail, head respectively
import random
guess = ''
count = 0
flag = True
while guess not in ('h', 't') and flag == True:
guess = input('\nGuess the coin toss! Enter heads or tails:')
guess = 1 if guess == 'h' else 0
toss = random.randint(0, 1) # 0 is tails, 1 is heads
print('toss result: ', 'h' if toss == 1 else 't')
print('win' if toss == guess else 'fail')
count += 1
if count == 3:
flag = False
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment