import pygame import sys import random import time rand1 = random.randint(1,255) rand2 = random.randint(1,255) rand3 = random.randint(1,255) pygame.init() pygame.display.set_caption("Task1") screen = pygame.display.set_mode((400, 300)) background = pygame.Surface ((400, 300)) surface = pygame.Surface((10, 10)) surface.fill((rand1,rand2,rand3)) Pos = [175, 125] while True: events = pygame.event.get() for event in events: if event.type == pygame.QUIT: pygame.quit() sys.exit() if event.type == pygame.KEYDOWN: if event.key == pygame.K_RIGHT: Pos [0] += 10 if event.type == pygame.KEYDOWN: if event.key == pygame.K_LEFT: Pos [0] -= 10 if event.type == pygame.KEYDOWN: if event.key == pygame.K_UP: Pos [1] -= 10 if event.type == pygame.KEYDOWN: if event.key == pygame.K_DOWN: Pos [1] += 10 rand1 = random.randint(1,255) rand2 = random.randint(1,255) rand3 = random.randint(1,255) screen.blit(background, (0, 0)) screen.blit(surface, Pos) pygame.display.update()