abbarnes

heads tails game

Apr 14th, 2023
866
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.41 KB | None | 0 0
  1. import random
  2.  
  3. def ht_game():
  4.     # user chooses h/t
  5.     choice = input("heads or tails")
  6.    
  7.     #flip a coin
  8.     coin = coin_flip()
  9.    
  10.     #announce win/loss
  11.     if choice == coin:
  12.         print("You won")
  13.     else:
  14.         print("You lost")
  15.  
  16.  
  17. def coin_flip():
  18.     flip = random.randint(1,2)
  19.     if flip == 1:
  20.         flip = "heads"
  21.     else:
  22.         flip = "tails"
  23.     return flip
  24.  
  25. ht_game()
Advertisement
Add Comment
Please, Sign In to add comment