In: Computer Science
Write a function, namely shape(s) that takes a positive integer s as the parameter and draws a square of length s. The square should be filled by a randomized color.
Then write another function, that calls the shape function to draw 4 squares as a 2x2 table.
Please answer in python.
Here is the code for the above question -
import turtle,random 
t = turtle.Turtle() 
def shape(s):
  colors  = ["red","green","blue","orange","purple","pink","yellow"] 
    
  # taking the input for the color 
  col = random.choice(colors)
    
  # set the fillcolor 
  t.fillcolor(col) 
    
  # start the filling color 
  t.begin_fill() 
    
  # drawing the square of side s 
  for _ in range(4): 
    t.forward(s) 
    t.right(90) 
    
  # ending the filling of the color 
  t.end_fill() 
s = int(input("Enter the length of the side of the square: "))
for i in range(2):
  for j in range(2):
    shape(s)
    t.forward(s);
  t.setpos(t.xcor(), t.ycor()-s);
  t.setpos(t.xcor()-2*s, t.ycor());
Here is the ss of the code and also the output -

Please give a big thumbs up
if you like the answer.
:)