def testDivide():
    assert (calculator.divide(-1,-7) == 1/7)
    assert (calculator.divide(-8,3) == -8/3)
    assert (calculator.divide(8,3) == 8/3)
    assert (calculator.divide(0,3) == 0)
    try:
        calculator.divide(5,0)
    except Exception as err:
        assert (str(err) == 'I\'m sorry, I can\'t divide by zero')
Example #2
0
import calculator

print(calculator.plus(10, 5))
print(calculator.minus(10, 5))
print(calculator.multiply(10, 5))
print(calculator.divide(10, 5))
    def test_divide(self):
        self.assertEqual(cl.divide(1, 2), 0.5)
        self.assertEqual(cl.divide(2, 1), 2)
        self.assertEqual(cl.divide(-1, 2), -0.5)
        self.assertEqual(cl.divide(1, -2), -0.5)
        self.assertEqual(cl.divide(-1, -2), 0.5)
        self.assertEqual(cl.divide(0, 2), 0)
        self.assertEqual(cl.divide(0, -2), 0)

        with self.assertRaises(ValueError):
            cl.divide(2, 0)

        with self.assertRaises(TypeError):
            cl.divide('abc', 2)
            cl.divide(2, 'abc')
            cl.divide(True, 2)
            cl.divide(2, True)
Example #4
0
import calculator  #.py는 생략

print(calculator.plus(10, 5))
print(calculator.minus(10, 5))
print(calculator.multiply(10, 5))
print(calculator.divide(10, 5))
 def test_int2_divide(self):
     self.assertEqual(calculator.divide(9, 0), "NaN")
 def divide(m, n):
     return c.divide(m, n)
Example #7
0
 def divide(self, m, n):
     return c.divide(m, n)
Example #8
0
def test_divide():
    assert calculator.divide(20, 4) == 5
Example #9
0
def test_numbers_divide_poz():
    assert divide(4, 2) == 2
Example #10
0
 def test_divide(self):
     """Is divide function working correctly"""
     self.assertEquals(divide(2, 2), 1)
Example #11
0
 def test_divide_integers_positive2(self):
     result = c.divide(7, 3)
     self.assertEqual(result, 2)
Example #12
0
 def test_divide_zero(self):
     result = c.divide(0, 2)
     self.assertEqual(result, 0)
Example #13
0
 def test_divide_integers_neg_pos2(self):
     result = c.divide(-7, 2)
     self.assertEqual(result, -3)
Example #14
0
 def test_divide_integers_pos_neg2(self):
     result = c.divide(9, -2)
     self.assertEqual(result, -4)
Example #15
0
 def test_divide_integers_negative2(self):
     result = c.divide(-7, -2)
     self.assertEqual(result, 3)
print('Great! Now enter the second number: ')
second = int(input())

choice = 0

#let's output a menu
while choice != 5:
    print('Choose what you\'d like to do with ' + str(first) + ' and ' + str(second) + ':')
    print('\t1: add')
    print('\t2: subtract')
    print('\t3: multiply')
    print('\t4: divide')
    print('\t5: exit')

    choice = int(input())

    # this series of if-statements call the proper functions from within the calculator program
    if choice == 1:
        print('The calculator returned: ' + str(calculator.add( first, second )))
    elif choice == 2:
        print('The calculator returned: ' + str(calculator.subtract( first, second )))
    elif choice == 3:
        print('The calculator returned: ' + str(calculator.multiply( first, second )))
    elif choice == 4:
        print('The calculator returned: ' + str(calculator.divide( first, second )))
    elif choice == 5:
        print('Goodbye!')
    else:
        print('Sorry that\'s not a valid choice. Try again.')
Example #17
0
 def test_operator(self):
   self.assertEqual(calculator.add(13,11),24)
   self.assertEqual(calculator.subtract(15,-10),25)
   self.assertEqual(calculator.divide(16,2),8)
   self.assertEqual(calculator.multiply(7,-3),-21)
Example #18
0
def test_numbers_divide_negative():
    assert divide(-4, -2) == 2
Example #19
0
 def test_division(self):
     assert 10 == calculator.divide(100, 10)
Example #20
0
def test_numbers_divide_neg_poz():
    assert divide(-4, 2) == -2
 def test_divide(self):
     self.assertEqual(calculator.divide(15, 3), 5)
Example #22
0
def test_divideby0():
    assert divide(2, 0) == "you can't divide by zero you idiot"
 def test_int_divide(self):
     self.assertEqual(calculator.divide(9, 3), 3)
Example #24
0
            strRightValue = input("Enter second number: ")
        rightValue = int(strRightValue)
    except ValueError:
        print("No.. input string is not a number. It's a string")
    if choice == '1':
        currentValue = calculator.add(leftValue, rightValue)
        print(leftValue, "+", rightValue, "=", currentValue)
        calculator.setMemoryValue(currentValue)
        print(calculator.getMemoryValue())

    elif choice == '2':
        currentValue = calculator.subtract(leftValue, rightValue)
        print(leftValue, "-", rightValue, "=", currentValue)
        calculator.setMemoryValue(currentValue)

    elif choice == '3':
        currentValue = calculator.multiply(leftValue, rightValue)
        print(leftValue, "*", rightValue, "=", currentValue)
        calculator.setMemoryValue(currentValue)

    elif choice == '4':
        currentValue = calculator.divide(leftValue, rightValue)
        print(leftValue, "/", rightValue, "=", currentValue)
        calculator.setMemoryValue(currentValue)
    elif choice == '5':
        currentValue = calculator.power(leftValue, rightValue)
        print(leftValue, "^", rightValue, "=", currentValue)
        calculator.setMemoryValue(currentValue)
    else:
        print("Invalid input")
 def test_float_divide(self):
     self.assertEqual(calculator.divide(5.4, 3), 1.8)
Example #26
0
def main():
    import tkinter as tk

    query = takeCommand()

    while(query != None):


        if ('answer of'  in query.lower() or  'calculate' in query.lower() or  '/' in query.lower()  or  'x' in query.lower()  or  '-' in query.lower()  or  '+' in query.lower()  or  'tan' in query.lower()  or  'sine' in query.lower()  or  'cosine' in query.lower() or  'power' in query.lower()):
            speak("Working on it...")
            string = query
            #calculate 10 + 10 
            string = re.findall('\d+', string)

            if (len(string) < 2):
                
                operand1 = int(string[0])
                # print(operand1)
                
                if 'sine'  in query.lower():
                    answer = sin(operand1)
                    speak("Answer is :"+str(answer))
                    InsertText("Answer is : "+ str(answer))
                elif 'cosine' in query.lower():
                    answer = cos(operand1)
                    speak("Answer is :"+str(answer))
                    InsertText("Answer is : "+ str(answer))
                elif 'tan'  in query.lower():
                    answer = tan(operand1)
                    speak("Answer is :"+str(answer))
                    InsertText("Answer is : "+ str(answer))
            else:
                operand1 = int(string[0])
                operand2 = int(string[1])
   
            # print("string: "+str(string))
            # print("operand1:"+str(operand1))
            # print("operand2:"+str(operand2))

                if ('+') in query.lower():
                    answer = Sum(operand1,operand2)
                    speak("Answer is :"+str(answer))
                    InsertText("Answer is : "+ str(answer))
            
                elif ('x') in query.lower():
                    answer = multiply(operand1,operand2)
                    speak("Answer is :"+str(answer))
                    output.delete('1.0',END)
                    InsertText("Answer is : "+ str(answer))


                elif ('/') in query.lower():
                    answer = divide(operand1,operand2)
                    speak("Answer is :"+str(answer))
                    InsertText("Answer is : "+ str(answer))


                elif ('-') in query.lower():
                    answer = subtract(operand1,operand2)
                    if int(answer) <0:
                        speak("Answer is negtive:"+str(answer))
                    else:
                        speak("Answer is : "+str(answer))                    
        
                    InsertText("Answer is : "+ str(answer))


                elif ('power') in query.lower():
                    answer = power(operand1,operand2)
                    speak("Answer is :"+str(answer))
                    InsertText("Answer is : "+ str(answer))

                else:
                    speak("This is so hard for me, Im sorry")
                    InsertText("This is so hard for me, Im sorry")


            break

        if ('wikipedia') in query.lower():
            speak('searching on wikipedia...')
            query = query.replace("wikipedia","")
            results = wikipedia.summary(query, sentences=2)
            # print(results)
            if results == False:
                speak("I didnt find any information")
                InsertText("I didnt find any information")
            else:
                print(results)
                InsertText(results)
                speak(results)
                
            break

        if ('search on google for' in query.lower()  or 'google for' in query.lower() or 'search for' in query.lower()):
            text = query
            text = text.replace('google','')
            text = text.replace('search on' or 'search for' or 'search about','')
            speak("Searching on google..")
            # InsertText("Searching on google..")
            
            links = googleSearch(text)
            speak('I found this links may it could help you...')
            # print(links)
            InsertText(links)                
            break

        if (('translate' in query.lower()) or ('french' in query.lower())  or ('spanish' in query.lower())  or ('german' in query.lower())  or ('italian' in query.lower())  ):
            if ('french') in query.lower():
                ret = toFrench(query)
                print(ret)
                speakforeigner(ret)
                InsertText(ret)
                voice = engine.getProperty('voices')[1] 
                engine.setProperty('voice', voice.id)

            elif ('german') in query.lower():
                ret = toGerman(query)
                print(ret)
                speakforeigner(ret)
                InsertText(ret)
                voice = engine.getProperty('voices')[1]
                engine.setProperty('voice', voice.id)
            
            elif ('spanish') in query.lower():
                ret = toSpanish(query)
                print(ret)
                speakforeigner(ret)
                InsertText(ret)
                voice = engine.getProperty('voices')[1]
                engine.setProperty('voice', voice.id)

            elif ('italian') in query.lower():
                ret = toItalian(query)
                print(ret)
                speakforeigner(ret)
                InsertText(ret)
                voice = engine.getProperty('voices')[1]
                engine.setProperty('voice', voice.id)

            elif ('portuguese') in query.lower():
                ret = toPortuguese(query)
                print(ret)
                speakforeigner(ret)
                InsertText(ret)
                voice = engine.getProperty('voices')[1]
                engine.setProperty('voice', voice.id)
                
            else:
                speakforeigner("Im sorry I dont understand this language")
                InsertText("Im sorry I dont understand this language")

            break

        if ('open youtube') in query.lower():
            url = "youtube.com"
            chrome_path="C:/Program Files (x86)/Google/Chrome/Application/chrome.exe %s"
            speak("hold on")
            webbrowser.get(chrome_path).open(url)
            break
 
        if ('open google'  in query.lower()   or 'google' in query.lower()) :
            url = "google.com"
            speak("Im wondering what are you looking for")
            chrome_path="C:/Program Files (x86)/Google/Chrome/Application/chrome.exe %s"
            webbrowser.get(chrome_path).open(url)
            break

        if 'open facebook' in query.lower():
            url = "facebook.com"
            chrome_path="C:/Program Files (x86)/Google/Chrome/Application/chrome.exe %s"
            speak("Im on it")
            webbrowser.get(chrome_path).open(url)
            break

        if 'open linkedin' in query.lower():
            url = "linkedin.com"
            chrome_path="C:/Program Files (x86)/Google/Chrome/Application/chrome.exe %s"
            speak("lets get professional")
            webbrowser.get(chrome_path).open(url)
            break

        if 'open stackover flow' in query.lower():
            url = "stackoverflow.com"
            chrome_path="C:/Program Files (x86)/Google/Chrome/Application/chrome.exe %s"
            speak("hold on")
            webbrowser.get(chrome_path).open(url)
            break

        if 'open soundcloud' in query.lower():
            url = "soundcloud.com"
            chrome_path="C:/Program Files (x86)/Google/Chrome/Application/chrome.exe %s"
            speak("Im on it")
            webbrowser.get(chrome_path).open(url)
            break

        if ('play music' or 'play my list' or 'open my playlist' or 'open my favorite songs')in query.lower():
            songs_dir = 'E:\\desktop\\FUN\\Myplaylist' 
            songs = os.listdir(songs_dir)
            speak("playlist shuffle..")
            InsertText('playlist shuffle..')
            
            print(songs)
            os.startfile(os.path.join(songs_dir, songs[0]))
            break

        if ('the time now' in query.lower() or 'time' in query.lower() or 'what time is it' in query.lower() or 'how much oclock' in query.lower()):
            time = timevalue
            speak("The time is")
            speak(time)
            InsertText(time)
            

            break

        if ('what is the date' in query.lower() or 'What date is it' in query.lower() or 'What day is it' in query.lower() or "today's date" in query.lower()):
            date = datevalue
            speak("Today is ")
            speak(date)
            InsertText(date)
            break

        if ('what is the temperature now' or 'What is the weather today' or 'is it hot today' or "is it cold today") in query.lower():
            temp = tempvalue
            speak("Today's temperture is ")
            speak(temp)
            InsertText(temp)
            break

        if ('open my code' or 'open code' or 'your code') in query.lower():
            code_dir = 'C:\\Users\\Abdullah\\AppData\\Local\\Programs\\Microsoft VS Code\\Code.exe' 
            os.startfile(os.path.join(code_dir))
            break

        if ('f*** you' or 'm**********r' or 'you are disgusting'  or 'ugly' or 'bitch' or 'you are stupid' or "you're stupid") in query.lower():
            speak('You are so rude, I will not respond to that')
            InsertText('You are so rude, I will not respond to that')
            break

        if ('love you' in query.lower() or 'would you marry me' in query.lower()):
            speak('oh, you are so sweet')
            InsertText('oh, you are so sweet')
            break

        if 'email to tina' in query.lower():
            try:
                speak("what should I send")
                content = takeCommand()
                to ='*****@*****.**'
                sendEmail(to,content)
                speak("Email has been sent successfully")
                break
            except Exception as e:
                print(e)
                speak("There is a problem in email security, please check it and try again")
                break

        if ('draw' in query.lower() or 'drew' in query.lower()):
            speak("Lets draw, to save you drawing just press control  S")
            InsertText('press " CTRL+S" to save your draw..')
            drawStart()
            
            break

        if ('game' in query.lower()):
            speak("lets play a game")
            InsertText("Have fun..")
            startGame()

            
            break
    
        else:
            speak("Im not sure I understand")
            speak("Say it again")
            InsertText("Im not sure I understand\nSay it again")
            query= takeCommand()
Example #27
0
 def test_division(self):
     assert 4 == calculator.divide(8, 2)
Example #28
0
 def testDivide(self):
     self.assertEqual(calculator.divide(4, 2), 2)
     self.assertEqual(calculator.divide(2, -4), -0.5)
     self.assertEqual(calculator.divide(22, 2), 11)
 def test_division(self):
     assert 512 == calculator.divide(1024, 2)
import calculator

number1 = int(input("What is the first number?"))
number2 = int(input("What is the second number?"))
operand = str(
    input(
        "Do you want to multiply, divide, subtract, or add? '*', '/', '-', '+'?"
    ))
result = 0

if operand == '*':
    result = calculator.multiply(number1, number2)
    print(f"{number1} times {number2} is {result}")
elif operand == '/':
    result = calculator.divide(number1, number2)
    print(f"{number1} divided by {number2} is {result}")
elif operand == '-':
    result = calculator.subtract(number1, number2)
    print(f"{number1} minus {number2} is {result}")
elif operand == '+':
    result = calculator.add(number1, number2)
    print(f"{number1} plus {number2} is {result}")
Example #31
0
        if operand == '+' or operand == '-' or operand == '*' or operand == '/':
            break
        else:
            print("Not a valid input, enter a '+', '-', '*', or a '/'")

    while True:
        try:
            number_2 = int(input('Enter num2: '))
            break
        except ValueError:
            print("Incorrect input: Not a number, try again.")

    if operand == "+":
        result = add(number_1, number_2)
    elif operand == '-':
        result = subtract(number_1, number_2)
    elif operand == '*':
        result = multiply(number_1, number_2)
    elif operand == '/':
        result = divide(number_1, number_2)
    else:
        print("ERROR: INVALID OPERAND")

    print("Your equation is {0} {1} {2} = {3}".format(number_1, operand,
                                                      number_2, result))

    cont = input("Press 'q' to quit or any other key to continue")
    if cont == 'q':
        break
Example #32
0
def test_divide():
    results = divide(6, 2)
    assert results == 3
Example #33
0
import calculator
a = int(input("Enter first number: "))
b = int(input("Enter second number: "))
print(a,"+",b,"=",calculator.add(a, b))
print(a,"-",b,"=",calculator.subtract(a, b))
print(a,"*",b,"=",calculator.multiply(a, b))
print(a,"/",b,"=",calculator.divide(a, b))
Example #34
0
def test_divide_by_zero():
    results = divide(99, 0)
    assert type(results) == str
Example #35
0
 def test_ZeroDivisionError(self):
   with self.assertRaises(ZeroDivisionError):
     calculator.divide(10,0)  
Example #36
0
def test_zero_division_raises_ZeroDivisionError_exercise_5():
    with pytest.raises(ZeroDivisionError):
        calculator.divide(1, 0)