External Exam Download Resources Web Applications Games Recycle Bin

Roll a dice

dice1.py

import pygame
pygame.init()
screen = pygame.display.set_mode((400, 300))
done = False

dice1 = pygame.image.load("dice1.bmp")
dice2 = pygame.image.load("dice2.bmp")

import random
if random.randint(1,2) == 1:
    dice = dice1
else:
    dice = dice2

while not done:
  for event in pygame.event.get():
    if event.type == pygame.QUIT:
      done = True

  screen.blit(dice, (150, 100))
  
  pygame.display.flip()
pygame.quit()
                    

put image files + python file into same folder: