A)Which of the following is an example of sequential-driven code?(1 point)

for i in range(x):
for j in range(y):
t.forward(z)
t.right(360 / y)
t.right(360 / x)
wn.listen()
wn.mainloop()

def h1():
t.forward(30)
def h2():
t.left(45)
def h3():
t.right(45)
wn.onkey(h1, "Up")
wn.onkey(h2, "Left")
wn.onkey(h3, "Right")

Wn.onkey(picture, "p")
wn.listen()
wn.mainloop()

wn.onclick(f)
wn.listen()
wn.mainloop()

A)Which of the following is an example of event-driven code?(1 point)

for i in range(x):
for j in range(y):
t.forward(z)
t.right(360 / y)
t.right(360 / x)

t = turtle.Turtle()
wn = turtle.Screen()
wn.setColor("red")
t.pd()
t.speed(0)

def h1():
t.forward(30)
wn.onkey(h1, "Up")

import turtle
t = turtle.Turtle()
wn = turtle.Screen()

1 answer

A) The example of sequential-driven code is:

for i in range(x):
    for j in range(y):
        t.forward(z)
        t.right(360 / y)
    t.right(360 / x)

This code runs in a sequential manner, executing the loops one after the other in a defined order.

B) The example of event-driven code is:

def h1():
    t.forward(30)
    
def h2():
    t.left(45)
    
def h3():
    t.right(45)

wn.onkey(h1, "Up")
wn.onkey(h2, "Left")
wn.onkey(h3, "Right")
wn.listen()
wn.mainloop()

This code involves event-driven programming as it responds to user input events (key presses in this case) to call the associated functions.