Coin flip guessing game with counter
coin flip guessing game with counter.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") wins = 0 losses = 0 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: wins = wins + 1 else: losses = losses + 1 if choose_tails.get_rect(topleft=(0,25)).collidepoint(click): if flip == 2: wins = wins + 1 else: losses = losses + 1 print("Wins:",wins,"Losses:",losses) pygame.display.flip() pygame.quit()
put all these image files + python file into same folder: