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

Responses

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

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

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

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

1 answer

The example of event-driven code from your options is:

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

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

In this code, the function h1 is defined to move the turtle forward when the "Up" key is pressed. This is a clear example of event-driven programming, where actions are triggered by specific events (in this case, a key press).