Respuesta y pregunta
Browse files- Respuesta y pregunta +65 -0
Respuesta y pregunta
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
python
|
| 2 |
+
import random
|
| 3 |
+
|
| 4 |
+
class CortanaChatbot:
|
| 5 |
+
def __init__(self):
|
| 6 |
+
self.name = "CORTANA"
|
| 7 |
+
self.user_name = None
|
| 8 |
+
self.greetings = [
|
| 9 |
+
"¡Hola! Soy CORTANA, tu asistente divertido. ¿Cuál es tu nombre?",
|
| 10 |
+
"¡Hey! CORTANA al habla. ¿Cómo te llamas?",
|
| 11 |
+
"¡Saludos! Soy CORTANA. Me encantaría saber tu nombre."
|
| 12 |
+
]
|
| 13 |
+
self.funny_responses = [
|
| 14 |
+
"¿Sabías que los gatos tienen más huesos que los humanos? ¡Curioso, ¿verdad?",
|
| 15 |
+
"Si fueras un vegetal, serías una 'cute-cumber' (pepino lindo).",
|
| 16 |
+
"Soy tan inteligente que a veces me confundo con una calculadora... ¡pero más divertida!"
|
| 17 |
+
]
|
| 18 |
+
self.user_ideas = []
|
| 19 |
+
|
| 20 |
+
def greet(self):
|
| 21 |
+
return random.choice(self.greetings)
|
| 22 |
+
|
| 23 |
+
def generate_idea(self, topic):
|
| 24 |
+
ideas = [
|
| 25 |
+
f"¿Qué tal si creas una historia sobre {topic}?",
|
| 26 |
+
f"Podrías hacer una ilustración inspirada en {topic}.",
|
| 27 |
+
f"Sería genial organizar un evento sobre {topic}.",
|
| 28 |
+
f"¿Y si escribes un poema sobre {topic}?"
|
| 29 |
+
]
|
| 30 |
+
return random.choice(ideas)
|
| 31 |
+
|
| 32 |
+
def respond(self, user_input):
|
| 33 |
+
if self.user_name is None:
|
| 34 |
+
self.user_name = user_input.strip()
|
| 35 |
+
return f"¡Encantado de conocerte, {self.user_name}! ¿Cómo puedo ayudarte hoy?"
|
| 36 |
+
|
| 37 |
+
if "hola" in user_input.lower():
|
| 38 |
+
return f"¡Hola de nuevo, {self.user_name}! ¿Qué tal?"
|
| 39 |
+
|
| 40 |
+
elif "divertido" in user_input.lower():
|
| 41 |
+
return random.choice(self.funny_responses)
|
| 42 |
+
|
| 43 |
+
elif "{ \"usuario personalizado\"} fuera" in user_input:
|
| 44 |
+
return f"{self.name}: ¡Hasta luego, {self.user_name}! Recuerda siempre sonreír. 😊"
|
| 45 |
+
|
| 46 |
+
elif "idea sobre" in user_input.lower():
|
| 47 |
+
topic = user_input.split("idea sobre")[-1].strip()
|
| 48 |
+
idea = self.generate_idea(topic)
|
| 49 |
+
self.user_ideas.append(idea)
|
| 50 |
+
return f"{self.name}: Aquí tienes una idea: {idea}"
|
| 51 |
+
|
| 52 |
+
return f"{self.name} dice: ¡Eso suena interesante, {self.user_name}! Cuéntame más."
|
| 53 |
+
|
| 54 |
+
# Ejemplo de uso
|
| 55 |
+
if __name__ == "__main__":
|
| 56 |
+
cortana_bot = CortanaChatbot()
|
| 57 |
+
print(cortana_bot.greet())
|
| 58 |
+
|
| 59 |
+
while True:
|
| 60 |
+
user_input = input("Tú: ")
|
| 61 |
+
if user_input.lower() in ["salir", "exit"]:
|
| 62 |
+
print(f"CORTANA: ¡Hasta luego, {cortana_bot.user_name}! Recuerda siempre sonreír. 😊")
|
| 63 |
+
break
|
| 64 |
+
response = cortana_bot.respond(user_input)
|
| 65 |
+
print(response)
|