ia.py

Created by hicham-choukour

Created on January 29, 2025

1.63 KB


# Type your text here
import math
import kandinsky as kd
import ion

def draw_interface():
    kd.fill_rect(0, 0, 320, 222, (255, 255, 255))  # Fond blanc
    kd.draw_string("NumWorks AI", 10, 10, (0, 0, 0), (255, 255, 255))
    kd.draw_string("> ", 10, 50, (0, 0, 0), (255, 255, 255))

def get_input():
    input_str = ""
    x, y = 25, 50
    while True:
        for key in range(256):
            if ion.keypad.keydown(key):
                if key == ion.keypad.KEY_OK:
                    return input_str
                elif key == ion.keypad.KEY_BACK:
                    input_str = input_str[:-1]
                elif key == ion.keypad.KEY_EXE:
                    return input_str
                elif 32 <= key <= 126:
                    input_str += chr(key)
                kd.fill_rect(25, 50, 300, 20, (255, 255, 255))
                kd.draw_string(input_str, 25, 50, (0, 0, 0))

def process_input(user_input):
    user_input = user_input.lower()
    responses = {
        "bonjour": "Bonjour! Comment puis-je t'aider?",
        "qui es-tu": "Je suis une IA simplifiee pour NumWorks.",
        "quel est le sens de la vie": "42, bien sûr!",
    }
    if user_input in responses:
        return responses[user_input]
    try:
        return str(eval(user_input))  # Calculer les expressions mathématiques simples
    except:
        return "Je ne comprends pas."

def main():
    draw_interface()
    while True:
        user_input = get_input()
        response = process_input(user_input)
        kd.fill_rect(25, 80, 300, 20, (255, 255, 255))  # Effacer la réponse précédente
        kd.draw_string(response, 25, 80, (0, 0, 0))

main()

During your visit to our site, NumWorks needs to install "cookies" or use other technologies to collect data about you in order to:

With the exception of Cookies essential to the operation of the site, NumWorks leaves you the choice: you can accept Cookies for audience measurement by clicking on the "Accept and continue" button, or refuse these Cookies by clicking on the "Continue without accepting" button or by continuing your browsing. You can update your choice at any time by clicking on the link "Manage my cookies" at the bottom of the page. For more information, please consult our cookies policy.