Created
January 1, 2020 16:12
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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