mensaje = "hola"
if mensaje == "hola":
print("IA: Hola, ¿cómo estás?")
elif mensaje == "como te llamas":
print("IA: Soy tu asistente.")
elif mensaje == "que puedes hacer":
print("IA: Por ahora puedo responder algunas cosas.")
else:
print("IA: Todavía no entiendo eso.")
This code defines a variable `mensaje` with the value `"hola"`, then checks it against several possible inputs using an if-elif-else chain. Since `mensaje` equals `"hola"`, it prints the greeting and skips the other conditions.
- The code works correctly for the fixed value, but think about how you could make it interactive so the user can type different messages instead of always using `"hola"`. What function in Python lets you get input from the user?
- Notice that the conditions only match exact strings. What happens if the user types `"Hola"` with a capital letter or adds extra spaces? How could you make the matching more flexible?