diff --git a/Stunde 2/Planung/gpt_idea.py b/Stunde 2/Planung/gpt_idea.py new file mode 100644 index 0000000..b22246a --- /dev/null +++ b/Stunde 2/Planung/gpt_idea.py @@ -0,0 +1,56 @@ +import random +import datetime + + +class ChatBot: + def __init__(self): + self.name = "PyBot" + + self.antworten = { + "hallo": "Hallo! Wie geht es dir?", + "wie heißt du": f"Ich bin {self.name}.", + "python": "Python ist eine beliebte Programmiersprache.", + "tschüss": "Bis bald!" + } + + self.standardantworten = [ + "Interessant.", + "Erzähl mir mehr.", + "Das verstehe ich.", + "Kannst du das genauer erklären?" + ] + + def antworten_auf(self, text): + text = text.lower() + + # Uhrzeit abfragen + if "uhrzeit" in text or "wie spät" in text: + jetzt = datetime.datetime.now() + return f"Es ist {jetzt.strftime('%H:%M:%S')} Uhr." + + # Bekannte Fragen durchsuchen + for frage in self.antworten: + if frage in text: + return self.antworten[frage] + + return random.choice(self.standardantworten) + + +def main(): + bot = ChatBot() + + print("ChatBot gestartet.") + print("Schreibe 'ende' zum Beenden.") + + while True: + nachricht = input("Du: ") + + if nachricht.lower() == "ende": + print("Bot: Auf Wiedersehen!") + break + + print("Bot:", bot.antworten_auf(nachricht)) + + +if __name__ == "__main__": + main() \ No newline at end of file