External Exam Download Resources Web Applications Games Recycle Bin

Coin flip guessing game

coin flip guessing game.py

import pygame, random
pygame.init()
screen = pygame.display.set_mode((400, 300))
done = False
choose_heads = pygame.image.load("choose_heads.png")
choose_tails = pygame.image.load("choose_tails.png")
coin = pygame.image.load("heads.gif")
while not done:
  screen.blit(choose_heads, (0, 0))
  screen.blit(choose_tails, (0, 25))
  screen.blit(coin, (200, 150))
  for event in pygame.event.get():
    if event.type == pygame.QUIT:
      done = True
    if event.type == pygame.MOUSEBUTTONDOWN:
      flip = random.randint(1,2)
      if flip == 1:
        coin = pygame.image.load("heads.gif")
      else:
        coin = pygame.image.load("tails.gif")
          
      click = pygame.mouse.get_pos()
      if choose_heads.get_rect(topleft=(0,0)).collidepoint(click):
        if flip == 1:
          print("you picked heads and won")
      if choose_tails.get_rect(topleft=(0,25)).collidepoint(click):
        if flip == 2:
          print("you picked tails and won")
          
  pygame.display.flip()
  
pygame.quit()
  
  

put all these image files + python file into same folder: