Don't wanna be here? Send us removal request.
Link
Hey Guys,
With the help of this article you can create a base rock paper scissor game with python which is super simple and recommended for beginner. Go try it and leave comments if your AI wins you!
#python#pythonprojects#pythonproject#pythonprogramming#rock paper scissors#pythonforbeginners#pythoncoolprojects#pythonforall#pytechtip#pythontips#projectsforbeginners#projectforbeginnersinpython#pythonpy#gameinpython#pythongame
2 notes
·
View notes
Text
Is Speaking Calculator Possible With Python??
Here is The Solution:
HI.
NOTE = (IN THIS BLOG I WILL TEACH YOU HOW TO CREATE A CALCULATOR IF YOU WANT TO MAKE IT SPEAKTHE CODE IS GIVEN BELOW GO CHECK IT).
IN THIS BLOG YOU'LL BE CREATING A PYTHON CALCULATOR BUT IT WILL PEAK TO YOU.
IT WILL BE SO INTERESTING AND FUN, SO LET'S GET STARTED....
FIRST OF ALL WE WILL INCLUDE (OR) IMPORT SOME PACKAGE TO MAKE THE CALCULATOR SPEAK. WE WILL BE USING PYTTSX3 TO MAKE THE CALCULATOR SPEAK AND SPEECH RECOGNITION TO LISTEN TO US WITH OUR MICROPHONE.
HERE IS HOW YOU WILL INSTALL THE PACKAGES:
OPEN COMMAND PROMPT(CMD).
IN THE FIRST LINE GIVE THIS COMMAND = (pip install pyttsx3)
AFTER THE INSTALLATION OF PYTTSX3 INSTALL SPEECH RECOGNITION WITH THIS COMMAND = (pip install SpeechRecognition).
AND ONE MORE PACKAGE IS IMPORTANT, THAT IS PYAUDIO INSTALL IT WITH THIS => (pip install PyAudio).
THAT'S ALL WE HAVE SUCCESSFULLY INSTALLED THE PACKAGES.
NOW LET'S DIVE INTO THE REAL CODE:
FIRST WE HAVE TO ALOT THE FUCTIONS FOR OPERATIONS.
FOR THIS THE CODE IS VERY SIMPLE AND EASY TO WRITE.
FOR DIFFERENT OPERATIONS WE HAVE TO CREATE DIFFERENT FUNCTIONS:
FOR ADDITION:
CODE:
def add(x, y): return x + y
THAT'S THE CODE FOR ADDITION FUCTION.
THIS FUCTION HAS 2 PARAMETERS NAMELY (X AND Y) SO IT MEANT THE X AND Y VARIABLE IS THE NUMBER WE ARE GOING TO GIVE TO ADD. SAME FOR ALL OPERATIONS.
FOR SUBTRACTION:
COD
E: def add(x, y): return x - y
THAT'S THE CODE FOR SUBTRACTION FUCTION.
THIS FUCTION HAS 2 PARAMETERS NAMELY (X AND Y) SO IT MEANT THE X AND Y VARIABLE IS THE NUMBER WE ARE GOING TO GIVE TO SUBTRACT. SAME FOR ALL OPERATIONS.
FOR MULTIPLICATION:
CODE:
def add(x, y): return x * y
THAT'S THE CODE FOR MULTIPLICATION FUCTION.
THIS FUCTION HAS 2 PARAMETERS NAMELY (X AND Y) SO IT MEANT THE X AND Y VARIABLE IS THE NUMBER WE ARE GOING TO GIVE TO MULTIPLY. SAME FOR ALL OPERATIONS.
FOR DIVISION:
CODE:
def add(x, y): return x / y
THAT'S THE CODE FOR DIVISION FUCTION.
THIS FUCTION HAS 2 PARAMETERS NAMELY (X AND Y) SO IT MEANT THE X AND Y VARIABLE IS THE NUMBER WE ARE GOING TO GIVE TO DIVIDE. SAME FOR ALL OPERATIONS.
SO AFTER COMPLETING THESE CODE FOR OPERATIONS NEXT IS TO GET THE USER INPUT. IT IS ALSO EASY:
GIVE THE NUMBERS FOR FOUR OPERATIONS HERE IS THE CODE:
print("Select operation.") print("1.Add") print("2.Subtract") print("3.Multiply")
print("4.Divide")
THEN GET THE INPUT FOR CHOICE:
CODE: choice = input("Enter you choice: ")
AFTER THAT CHECK THE INPUTS WITH THIS CODE:
if choice in ('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))
IN THIS CODE WE WILL CHECK THAT IF THE USER GAVE THE CORRECT INPUT OF THE OPERATION LISTED ABOVE IFIT I CORRECT THE WE WILL CALL THE FUCTION OF THE SPECIFIC OPERATION THAT USER GAVE.
AND AT LAST:
WE WILL ASK THE USER THAT IF HE/SHE WANT ANOTHER CALCULATION WITH THIS SIMPLE LINE OF CODE:
# check if user wants another calculation # break the while loop if answer is no �� next_calculation = input("Let's do next calculation? (yes/no): ") if next_calculation == "no": break else: print("Invalid Input")
THAT'S ALL WE HAVE CREATED A CALCULATOR.
HERE IS THE FULL CODE FOR CALCULATOR:
--------------------------------------------------------------------------------------------------------------------------# This function adds two numbersdef add(x, y): return x + y
# This function subtracts two numbersdef subtract(x, y): return x - y
# This function multiplies two numbersdef multiply(x, y): return x * y
# This function divides two numbersdef divide(x, y): return x / y
print("Select operation.")print("1.Add")print("2.Subtract")print("3.Multiply")print("4.Divide")
while True: choice = input("Enter you choice: ")
if choice in ('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))
# check if user wants another calculation # break the while loop if answer is no next_calculation = input("Let's do next calculation? (yes/no): ") if next_calculation == "no": break else: print("Invalid Input")-------------------------------------------------------------------------------------------------------------------------
HERE IS THE CODE FOR SPEAKING CALCULATOR:-----------------------------------------------------------------------------------------------------------------------------
import speech_recognition as sr import pyttsx3 engine = pyttsx3.init() def speak(audio): engine.say(audio) engine.runAndWait() # Program make a simple calculator # This function adds two numbers def add(x, y): return x + y # This function subtracts two numbers def subtract(x, y): return x - y # This function multiplies two numbers def multiply(x, y): return x * y # This function divides two numbers def divide(x, y): return x / y def takeCommand(): #It takes microphone input from the user and returns string output r = sr.Recognizer() with sr.Microphone() as source: print("Listening...") r.pause_threshold = 1 audio = r.listen(source) try: print("Recognizing...") query = r.recognize_google(audio, language='en-in') # Using google for voice recognition. print(f"User said: {query}\n") # User query will be printed. except Exception as e: # print(e) print("Say that again please...") # Say that again will be printed in case of improper voice return "None" # None string will be returned return query print("Select operation.") print("1.Add") print("2.Subtract") print("3.Multiply") print("4.Divide") while True: mic = input("Whether your Microphone is working orr not? (yes/no): ") # take input from the user print('enter your choice: ') speak('enter your choice:') if(mic == "yes"): choice = takeCommand() else: choice = input("Enter you choice: ") # check if choice is one of the four options if choice in ('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)) # check if user wants another calculation # break the while loop if answer is no speak("Let's do next calculation? (yes or no): ") next_calculation = input("Let's do next calculation? (yes/no): ") if next_calculation == "no": break else: print("Invalid Input")
-----------------------------------------------------------------------------------------------------------------------------
THANK YOU FOR VISITING AND I HOPE IT IS USEFUL AND YOU GOT SOME NEW INFORMATION AND DONE A CRAZY PROJECT WITH PYTHON.
#python#calculator#python projects#python programming#python for beginners#beginner project#beginner project in python#Speaking calculator#python calculator#calculator with python#english#tutorial#python tutorial#pytechtip#pytechtip.com#crazy project#crazy project with python
5 notes
·
View notes