abbarnes icon

heads tails game

abbarnes | PRO | 04/14/23 07:54:16 PM UTC | 0 ⭐ | 824 👁️ | Never ⏰ | []
Python |

410 B

|

None

|

0 👍

/

0 👎

import random
 
def ht_game():
    # user chooses h/t 
    choice = input("heads or tails")
    
    #flip a coin
    coin = coin_flip()
    
    #announce win/loss
    if choice == coin:
        print("You won")
    else:
        print("You lost")
 
 
def coin_flip():
    flip = random.randint(1,2)
    if flip == 1:
        flip = "heads"
    else:
        flip = "tails"
    return flip 
 
ht_game()

Comments