コード例 #1
0
    def calculate_result(self, new_input: str):

        if self.dialog.lineEditResult.text() == '':
            self.dialog.lineEditResult.setText(new_input)

        else:
            cache_number = int(self.dialog.lineEditResult.text())
            target_operator = self.dialog.labelOperator.text()
            try:
                new_number = int(new_input)

                if target_operator == '+':
                    result = operations.addition(cache_number, new_number)
                elif target_operator == '-':
                    result = operations.minus(cache_number, new_number)
                elif target_operator == '*':
                    result = operations.multiplication(cache_number,
                                                       new_number)
                elif target_operator == '/':
                    if new_number == 0:
                        self.throw_error()
                    else:
                        result = operations.division(cache_number, new_number)

                self.dialog.lineEditInput.setText('')
                self.dialog.lineEditResult.setText(str(result))
            except:
                self.throw_error()
コード例 #2
0
def operate(choice):
    if choice == 1:
        number_1 = input("\nEnter First number")
        number_2 = input("\Enter second number")
        result = "Sum of " + number_1 + 'and' + number_2 + 'is:' + str(
            operations.add(int(float(number_1)), int(float(number_2))))
        return result
    if choice == 2:
        number_1 = input("\nEnter First number")
        number_2 = input("\Enter second number")
        result = "Sum of" + number_1 + 'and' + number_2 + 'is:' + str(
            operations.subtract(int(float(number_1)), int(float(number_2))))
        return result
    if choice == 3:
        number_1 = input("\nEnter First number")
        number_2 = input("\Enter second number")
        result = "Sum of" + number_1 + 'and' + number_2 + 'is:' + str(
            operations.multiplication(int(float(number_1)), int(
                float(number_2))))
コード例 #3
0
ファイル: main.py プロジェクト: SanjayMarreddi/Calculator
    Sigmoid of sum        -->  9     Random Number   -->  10
    Highest common factor --> 11     Factorial (of first number) --> 12
    Exponential of number --> 13     Sine (sinx)    --> 14
    Exit                  --> 17     Cosine(cosx)   --> 15 
                                     Tangent(tanx)  --> 16
   
    """)

    operator = int(input("Please Enter Your Choice :--> "))

    if operator == 1:
        result = addition(num1, num2)
    elif operator == 2:
        result = subtraction(num1, num2)
    elif operator == 3:
        result = multiplication(num1, num2)
    elif operator == 4:
        result = division(num1, num2)
    elif operator == 5:
        result = integer_division(num1, num2)
    elif operator == 6:
        result = power(num1, num2)
    elif operator == 7:
        result = modulo(num1, num2)
    elif operator == 8:
        result = log(num1, num2)
    elif operator == 9:
        result = sigmoid(num1 + num2)
    elif operator == 10:
        result = rand_between(num1, num2)
    elif operator == 11:
コード例 #4
0
ファイル: lab5a.py プロジェクト: dariusrenj/Python
 print("5. Power")
 print("6. Algorithms")
 print("7. Quit")
 print("{:_^20}").format("")
 #ask user what they want to do
 user_choice = user_input.check_int()
 print("{:_^20}").format("")
 #call function based on user choice
 if (user_choice == 1):
     operations.addition()
 elif (user_choice == 2):
     operations.subtraction()
 elif (user_choice == 3):
     operations.division()
 elif (user_choice == 4):
     operations.multiplication()
 elif (user_choice == 5):
     operations.power()
 elif (user_choice == 6):
     #let user choose what algorithm they want to run
     print("You selected algorithms.")
     print("1. Fibanacci")
     print("2. Pythagoras")
     user_choice2 = user_input.check_int()
     while (True):
         if (user_choice2 == 1):
             y = int(raw_input("How many times would you like to loop?\n"))
             print("{:_^20}").format("")
             while (True):
                 for i in xrange(y):
                     print(operations.fibonacci(i))
コード例 #5
0
ファイル: test.py プロジェクト: renatojobal/python_sol
 def test_multiplication(self):
     self.assertEqual(operations.multiplication(10, 10), 100)
コード例 #6
0
def add_operation(a, b):
    add = op.addTwoNumbers(a, b)
    mult = op.multiplication(a, b)
    div = op.division(a, b)
    return {"suma": add, "multiplicacion": mult, "division": div}