Ask coding questions

← Back to all posts
4.9.6 Random Color Square (Python)
Kyled2

Hey there, I'm new to coding and am struggling quite a lot. The program wants a (480, 400) rectangle that is randomly colored. Could you help me out?

The problem says:
import random

set_size(480, 400)

This graphics program should draw a square.

The fill color should be randomly choosen from

the COLORS list

SIDE_LENGTH = 100
COLORS = [Color.red, Color.orange, Color.yellow, Color.green, Color.blue,
Color.purple, Color.black, Color.gray]

Voters
Kyled2
Comments
hotnewtop
Saml2020

Python's random libary should help with that.

Here's an example.

Everytime you run the code, it will pick a random thing from the list and print it.