← Back to Community
How can one draw a birthday cake using a function, variables and a loop
Profile icon
MercyMuchangi

How can I change the color of the layers of the cake

Voters
Profile icon
Alex-Nguyen-Ngo
Profile icon
JuliePerez
Profile icon
Mushyroomy
Profile icon
LiamMcElroy
Profile icon
MercyMuchangi
Comments
hotnewtop
Profile icon
PattanAhmed

@MercyMuchangi Hi,
From your code, you may get something like this
Code:-

import turtle import random t = turtle.Turtle() x = random.randint(10, 200) y = random.randint(20, 100) for i in ['red', 'green', 'yellow', 'blue']: t.color(i) t.forward(x) t.left(90) t.forward(y)

If you want range function too, I think it's not possible as the output of this code is not like your code output.
Code with range:-

import turtle import random t = turtle.Turtle() x = random.randint(10, 200) y = random.randint(20, 100) for i in ['red', 'green', 'yellow', 'blue']: for z in range(2): t.color(i) t.forward(x) t.left(90) t.forward(y)

Hope this helps
Please mark my answer if this helps

Profile icon
DEMONul1234

t = turtle.Pen()
t.pencolor('Red')
t.speed(30)
for i in range(100):
t.forward(100)
t.left(91)
It creates a circle, remember to use .pencolor("insert color name here") to add colors