Skip to content
Sign upLog in
This post is read-only. Explore Repls and connect with other creators on Community.View Community
The info in this post might be out of date, check out our docs instead. View docs
1

4.9.6 Random Color Square (Python)

Kyled2
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]

1 year ago

Voters

Comments

TopNew
1
SamDev7
SamDev7

Python's random libary should help with that.

Here's an example.

import random fruits = ['apple','banana','orange','grape'] lunch = random.choice(fruits) print("I will get " + lunch + " for lunch.")

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

1 year ago
Load more