Ask coding questions

← Back to all posts
How can one draw a birthday cake using a function, variables and a loop
MercyMuchangi (3)

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

Comments
hotnewtop
PattanAhmed (1406)

@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

DEMONul1234 (54)

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