def testing_function_calculator(): assert calculator(3, 4, "*") == 12 assert calculator(3, 4, "/") == 0 assert calculator(3.0, 4, "/") == 0.75 assert calculator("a", "b", "+") == "ab" assert calculator("a", 4, "*") == "aaaa" return "testing_function_calculator() passed successfully"
def execute_cmd(cmd): global startTime if cmd == 'ctime': now = datetime.datetime.now() speak("Сейчас {0}:{1}".format(str(now.hour), str(now.minute))) elif cmd == "findFilmInfoInCinema": cpm.cinemaParser(cmd) elif cmd == "findFilms": cpm.cinemaParser(cmd) elif cmd == 'timer': timer.time_r() elif cmd == 'shutdown': os.system('shutdown -s') speak("Выключаю...") elif cmd == 'calc': calc.calculator() elif cmd == 'weather': weather.check_weather() elif cmd == 'conv': convert.convertation() elif cmd == 'translator': translate.translate() elif cmd == 'stupid1': anekdot.fun() elif cmd == 'internet': browser.browser() elif cmd == 'startStopwatch': speak("Секундомер запущен") startTime = time.time() elif cmd == "find": browser_find.google_find() elif cmd == "stopStopwatch": if startTime != 0: Time = time.time() - startTime speak( f"Прошло {round(Time // 3600)} часов {round(Time // 60)} минут {round(Time % 60, 2)} секунд" ) startTime = 0 else: speak("Секундомер не включен") elif cmd == 'deals': speak("Голова пока цела. Я имею ввиду процессор.") else: print("Команда не распознана")
def calc(): if request.method == "POST": number1 = request.form['number1'] number2 = request.form['number2'] oper = request.form['oper'] return render_template("calc.html", result=calculator(number1, number2, oper), num1=number1, num2=number2, op=oper) else: return render_template("calc.html")
def calculator(update, context): try: user_text = update.message.text.split()[1:] text = '' for parts in user_text: text += parts print(text) answer = calc.calculator(text) if type(answer) is str: update.message.reply_text(answer) elif type(answer) is float: update.message.reply_text('{:.2f}'.format(answer)) except: update.message.reply_text('Введены неверные данные')
def __init__(self): """initial function that sets values to class variables """ self.pCalc = calculator() self.playerNum = '' self.formatedHandVal = '' self.pointInPlay = '' self.holeCards = {'Hole 1': '', 'Hole 2': ''} self.commCards = { 'Flop 1': '', 'Flop 2': '', 'Flop 3': '', 'Turn': '', 'River': '' }
def test_sub(): assert calculator('-', 3, 1) == 2
def test_add(): assert calculator('+', 1, 3) == 4
def test_div(): assert calculator('/', 36, 6) == 6
#Importing the module calc import calc #Getting user input a = int(input("Enter first number:")) b = int(input("Enter second number:")) print("1-Addition 2-Subtraction 3-Multiplication 4.Divisoin 5.Power") while True: c = int(input("Enter Choice:")) if c > 5: break else: #Using the function calculator in calc module to perform the action print("The result is ", calc.calculator(a, b, c)) #Output '''Enter first number:5 Enter second number:5 1-Addition 2-Subtraction 3-Multiplication 4.Divisoin 5.Power Enter Choice:5 The result is 3125 Enter Choice:3 The result is 25 Enter Choice:4 The result is 1.0 Enter Choice:6 >>> '''
for ar in article: results.append(ar["title"]) for i in range(len(results) - 5): print(i + 1, results[i]) SpeakText(results[i]) if "time" in a: now = datetime.now() current_time = now.strftime("%H:%M:%S") SpeakText(current_time) if "date" in a: today = date.today() print("Today date is: ", today) SpeakText(today) if "calculator" in a: calc.calculator() if "song" in a: mixer.init() mixer.music.load("song.mp3") mixer.music.set_volume(0.7) mixer.music.play() while True: print("Press 'p' to pause, 'r' to resume") print("Press 'e' to exit the program") query = input(" ") if query == 'p': mixer.music.pause() elif query == 'r': mixer.music.unpause()
def test_add(self): cl = calculator(10, 5) self.assertEqual(calculator.add(cl), 15) self.assertEqual(calculator.add(calculator(-5, 5)), 0) self.assertEqual(calculator.add(calculator(-6, -5)), -11)
from calc import calculator first_text = "" operations = ["+", "-", "*", "/", "^"] while True: calculation_text = first_text + input("Enter your calculation: " + first_text) for o in operations: if len(calculation_text.split(o)) == 2: first_text = str( calculator(float(calculation_text.split(o)[0]), float(calculation_text.split(o)[1]), o))
def run_hive(): command = take_command() print(command) if 'hive' in command: command = command.replace('hive', '') print('Command: ' + command) if 'play' in command: song = command.replace('play', '') talk('playing ' + song) pywhatkit.playonyt(song) elif 'qtalk' in command: qtalk(listener) elif 'news' in command: print('This feature isnt available yet. Please check back soon.') elif 'question' in command: print('WolframAlpha is now loading!') qt() elif 'help' in command: print('WolframAlpha is now loading!') qt() elif 'save' in command: hivelog.save() elif 'joke' in command: res = requests.get('https://icanhazdadjoke.com/', headers={"Accept": "application/json"}) if res.status_code == requests.codes.ok: talk(str(res.json()['joke'])) else: talk('oops!I ran out of jokes') elif 'hey' in command: print('hey there') elif 'date' in command: now = datetime.datetime.now() talk("Current date and time : ") talk(now.strftime("%d %m %Y")) print("Current date and time : ") print(now.strftime("%d/%m/%Y")) engine.setProperty("rate", 178) elif 'calculator' in command: calc.calculator() elif 'who is' in command: person = command.replace('who is', '') info = wikipedia.summary(person, 1, auto_suggest=False) print(info) talk(info) elif 'question' in command: qt() elif 'what is pi' in command: print(math.pi) elif 'version' in command: print(var.version) elif 'quote' in command: print('This Feature is coming soon!') talk('This Feature is coming soon!') elif 'hi' in command: talk('Hello, i dont know you. Whats your name') name = input('Whats your name?: ') talk('Hi, ' + name + 'How are you?') har = input('How are you?') talk('You are,,,. ' + har + 'Thats Great,,, ' + name + 'Have,a great Day!') ## WEATHER CONFIG COMMANDS elif 'current weather' in command: weatherhive.newweather() elif 'current wind' in command: weatherhive.windw() elif 'current temp' in command: weatherhive.tempw() elif 'cloud' in command: weatherhive.cloudw() ## END OF WEATHER CONFIG COMMANDS elif 'shut down' in command: talk('Shutting all Hive Systems Down.') talk('Thank you for using hive! Goodbye!') print('Thank you for using H.I.V.E!') exit() elif 'exit' in command: talk('Shutting all Hive Systems Down.') talk('Thank you for using hive! Goodbye!') print('Thank you for using H.I.V.E!') exit() elif 'awesome thanks' in command: talk('Your, Welcome!') elif 'thanks' in command: talk('Ny Pleasure!') elif 'thank you' in command: talk('No Problem!') elif 'awesome' in command: talk('No Problem, is there anything i, can help you, with?') elif ' no' in command: talk('ok!') elif 'yes' in command: talk('Ok, what is it?') elif 'how are you' in command: talk('I am Great! ,, How are you!?') input('How are you?: ') print('Thats Good!') elif 'wake up' in command: talk('Yes sir, how can i be of help today?') elif 'you still there' in command: talk('Yes Sir, i am ready for your command!') elif 'who are you' in command: talk( 'My name is Hive. It stands for Home Assistant Intergrated Virtual Environment. I am here to help you with whatever i can' ) elif 'hello' in command: talk('hello, how are you today?') har = input('How are you?: ') talk('You are,,,. ' + har + 'Thats Great,,, ' + 'Have,a great Day!') else: print('Please say the command again.') talk('Invalid Command!') input('Please Type Your Command: ') take_command()
def main(): try: with sr.Microphone() as source2: print("noise redn") r.adjust_for_ambient_noise(source2, duration=0.5) print("listening") ChatLog.config(state=NORMAL) ChatLog.insert(END, "Vision: " + "listening" + '\n\n') ChatLog.config(foreground="#442265", font=("Verdana", 12)) ChatLog.config(state=DISABLED) ChatLog.yview(END) audio2 = r.listen(source2) print("converting") MyText = r.recognize_google(audio2) MyText = MyText.lower() print("Did you say " + MyText) ChatLog.config(state=NORMAL) ChatLog.insert(END, "You: " + str(MyText) + '\n\n') ChatLog.config(foreground="#145465", font=("Verdana", 12)) ChatLog.config(state=DISABLED) ChatLog.yview(END) a = MyText.split(" ") print(a) if "read" in a and "email" in a: content = readmail.readmymail() ChatLog.config(state=NORMAL) ChatLog.insert(END, "Vision: subject: " + str(content[0]) + '\n\n') ChatLog.insert(END, "Vision: from: " + str(content[1]) + '\n\n') ChatLog.config(foreground="#442265", font=("Verdana", 12)) ChatLog.config(state=DISABLED) ChatLog.yview(END) elif "email" in a: s = smtplib.SMTP('smtp.gmail.com', 587) s.starttls() s.login("*****@*****.**", "65477412") SpeakText("Please say the receiver's name") receive = "did not get" message = "not clear" ChatLog.config(state=NORMAL) ChatLog.insert( END, "Vision: " + "Please say the receiver's name" + '\n\n') ChatLog.config(foreground="#442265", font=("Verdana", 12)) ChatLog.config(state=DISABLED) ChatLog.yview(END) try: with sr.Microphone() as source2: audio2 = r.listen(source2) receive = r.recognize_google(audio2) print(receive) except sr.UnknownValueError: SpeakText("message was not clear") ChatLog.config(state=NORMAL) ChatLog.insert(END, "You: " + receive + '\n\n') ChatLog.config(foreground="#442265", font=("Verdana", 12)) ChatLog.config(state=DISABLED) ChatLog.yview(END) if receive.lower() in emaildb: receive = receive.lower() emailid = emaildb[receive] ChatLog.config(state=NORMAL) ChatLog.insert(END, "vision: " + "please say your message" + '\n\n') ChatLog.config(foreground="#442265", font=("Verdana", 12)) ChatLog.config(state=DISABLED) ChatLog.yview(END) SpeakText("Please say your message") try: with sr.Microphone() as source2: audio2 = r.listen(source2) message = r.recognize_google(audio2) except sr.UnknownValueError: SpeakText("message was not clear") ChatLog.config(state=NORMAL) ChatLog.insert(END, "You: " + message + '\n\n') ChatLog.config(foreground="#442265", font=("Verdana", 12)) ChatLog.config(state=DISABLED) ChatLog.yview(END) SpeakText("Sending") s.sendmail("*****@*****.**", emailid, message) s.quit() print("email sent") SpeakText("email sent") elif "help" in a or "helpdesk" in a: helpdesk.helpdesk() elif "settings" in a or "adjust" in a or "setting" in a: settings.settings() elif "weather" in a: report = API.weather_api() ChatLog.config(state=NORMAL) ChatLog.insert(END, "Vision: city: " + report[0] + '\n\n') ChatLog.insert(END, "Vision: temperature: " + report[1] + '\n\n') ChatLog.insert(END, "Vision: humidity: " + report[2] + '\n\n') ChatLog.insert(END, "Vision: pressure: " + report[3] + '\n\n') ChatLog.insert(END, "Vision: forecast: " + report[4] + '\n\n') ChatLog.config(foreground="#442265", font=("Verdana", 12)) ChatLog.config(state=DISABLED) ChatLog.yview(END) elif "app" in a or "application" in a: syspgm.openfile() elif "news" in a or "new" in a: results = API.news_api() for i in range(len(results) - 5): print(i + 1, results[i]) SpeakText(results[i]) ChatLog.config(state=NORMAL) ChatLog.insert(END, "Vision: " + str(results[i]) + '\n\n') ChatLog.config(foreground="#442265", font=("Verdana", 12)) ChatLog.config(state=DISABLED) ChatLog.yview(END) elif "time" in a: now = datetime.now() current_time = now.strftime("%H:%M:%S") SpeakText(current_time) ChatLog.config(state=NORMAL) ChatLog.insert(END, "Vision: " + str(current_time) + '\n\n') ChatLog.config(foreground="#442265", font=("Verdana", 12)) ChatLog.config(state=DISABLED) ChatLog.yview(END) elif "date" in a or "day" in a: today = date.today() print("Today date is: ", today) ChatLog.config(state=NORMAL) ChatLog.insert(END, "Vision: " + str(today) + '\n\n') ChatLog.config(foreground="#442265", font=("Verdana", 12)) ChatLog.config(state=DISABLED) ChatLog.yview(END) SpeakText(today) elif "calculator" in a: calc.calculator() elif "song" in a or "music" in a: ChatLog.config(state=NORMAL) ChatLog.insert(END, "Vision: " + "Press P to pause." + '\n') ChatLog.insert(END, "Vision: " + "Press r to Resume." + '\n') ChatLog.insert(END, "Vision: " + "Press e to exit music player." + '\n') ChatLog.config(foreground="#442265", font=("Verdana", 12)) ChatLog.config(state=DISABLED) ChatLog.yview(END) music.play_music() elif "detect" in a or "find" in a or "detection" in a: result = True while (result): ret, frame = videoCaptureObject.read() cv2.imwrite("./input/NewPicture.jpg", frame) result = False videoCaptureObject.release() cv2.destroyAllWindows() detection = detector.detectObjectsFromImage( input_image=input_path, output_image_path=output_path) ChatLog.config(state=NORMAL) ChatLog.insert(END, "Vision: " + "itemas detected are" + '\n') ChatLog.config(foreground="#442265", font=("Verdana", 12)) ChatLog.config(state=DISABLED) ChatLog.yview(END) for eachItem in detection: print(eachItem["name"]) ChatLog.config(state=NORMAL) ChatLog.insert(END, "Vision: " + eachItem["name"] + '\n') ChatLog.config(foreground="#442265", font=("Verdana", 12)) ChatLog.config(state=DISABLED) ChatLog.yview(END) SpeakText(eachItem["name"]) elif "whatsapp" in a: SpeakText("Who is the receiver") try: with sr.Microphone() as source2: audio2 = r.listen(source2) receive = r.recognize_google(audio2) print(receive) except sr.UnknownValueError: SpeakText("message was not clear") if receive.lower() in whatsappdb: receive = receive.lower() phno = whatsappdb[receive] SpeakText("say your message") try: with sr.Microphone() as source2: audio2 = r.listen(source2) message = r.recognize_google(audio2) print(message) except sr.UnknownValueError: SpeakText("message was not clear") whatsapp.whatsappmsg(message, phno) SpeakText("Sending message") SpeakText("Message sent") else: SpeakText("receiver not available") elif "message" in a or "sms" in a: SpeakText("Who is the receiver") try: with sr.Microphone() as source2: audio2 = r.listen(source2) receive = r.recognize_google(audio2) print(receive) except sr.UnknownValueError: print("message was not clear") if receive.lower() in whatsappdb: receive = receive.lower() phno = whatsappdb[receive] SpeakText("say your message") try: with sr.Microphone() as source2: audio2 = r.listen(source2) message = r.recognize_google(audio2) print(message) except sr.UnknownValueError: SpeakText("message was not clear") sms.send_sms(message, phno) else: SpeakText("receiver not available") except sr.RequestError as e: print("Could not request results; {0}".format(e)) except sr.UnknownValueError: print("unknown error occured") ChatLog.config(state=NORMAL) ChatLog.insert( END, "Vision: " + "Sorry! I Could not understand you." + '\n') ChatLog.config(foreground="#442265", font=("Verdana", 12)) ChatLog.config(state=DISABLED) ChatLog.yview(END)
def setUp(self): self.set1 = calculator(10, 6) self.set2 = calculator(-5, 5) self.set3 = calculator(-6, -5) self.set4 = calculator(-6, 0)