Posts

Showing posts with the label python

python code for calculator

 Here is an example of a simple calculator program written in Python: Python Copy code def add(x, y):     return x + y def subtract(x, y):     return x - y def multiply(x, y):     return x * y def divide(x, y):     return x / y print("Select operation.") print("1.Add") print("2.Subtract") print("3.Multiply") print("4.Divide") choice = input("Enter choice(1/2/3/4): ") num1 = float(input("Enter first number: ")) num2 = float(input("Enter second number: ")) if choice == '1':     print(num1, "+", num2, "=", add(num1, num2)) elif choice == '2':     print(num1, "-", num2, "=", subtract(num1, num2)) elif choice == '3':     print(num1, "*", num2, "=", multiply(num1, num2)) elif choice == '4':     print(num1, "/", num2, "=", divide(num1, num2)) else:     print("Invalid Input") This program allows...

how to make artificial intelligence like jarvis

I can provide you with an example of a basic Python script for a personal assistant AI, however, keep in mind that creating a full-fledged personal assistant AI requires a lot of resources and advanced programming skills. Here is an example of a basic Python script for a personal assistant AI using the SpeechRecognition and pyttsx3 libraries: Python ' import speech_recognition as sr import pyttsx3 def speak(text):     engine = pyttsx3.init()     engine.say(text)     engine.runAndWait() def get_audio():     r = sr.Recognizer()     with sr.Microphone() as source:         audio = r.listen(source)         said = ""         try:             said = r.recognize_google(audio)             print(said)         except Exception as e:             print("Exception: " + str(e))  ...