Esempio n. 1
0
def calculator():
    print('\n1. addition\n\n2. sutraction\n\n3. multiplication\n\n4. division')
    choice=input('\nchoisi un\n')
    ready_to_quit(choice)
    if choice=='1':
        addition()
    if choice=='2':
        subtraction()
    if choice=='3':
        multiplication()
    if choice=='4':
        division()
Esempio n. 2
0
 def LaunchModule(self):
     if self.num1 < self.num2:  #swapping Number.. num1 must be greater than num2
         tmp = self.num1
         self.num1 = self.num2
         self.num2 = tmp
     if self.ButtonIndex == 0:
         obj = addition.addition(self, -1, "Addition", self.num1, self.num2,
                                 self.fontsize, self.speed)
         print 'after in addition'
     elif self.ButtonIndex == 1:
         print 'before'
         obj = subtraction.subtraction(self, -1, "Subtraction", self.num1,
                                       self.num2, self.fontsize, self.speed)
         print 'after'
     elif self.ButtonIndex == 2:
         obj = Multiplication.multiplication(self, -1, "Multiplication",
                                             self.num1, self.num2,
                                             self.fontsize, self.speed)
     elif self.ButtonIndex == 3:
         obj = FullLongDiv.LongDiv(self, -1, "Long Division", self.num1,
                                   self.num2, self.fontsize, self.speed)
     elif self.ButtonIndex == 4:
         obj = lcm.lcm(self, -1, "Least Common Multiple", self.num1,
                       self.num2, self.fontsize, self.speed)
     obj.Bind(wx.EVT_CLOSE, self.StartTimer)
Esempio n. 3
0
def getMenuChoice():
    #Prints menu options
    def menu():
        print(30 * "-", "Arithmetic Calculator", 30 * "-")
        print("1. Addition Calculator ")
        print("2. Subtraction Calculator ")
        print("3. Multiplication Calculator ")
        print("4. Division Calculator ")
        print("5. Exit Calculator ")
        print(83 * "-")

    loop = True
    int_choice = -1
    # While loop is True, continue iterating until False.
    while loop:
        menu()  # Displays menu
        choice = input("Enter your choice [1-5]: ")

        if choice == '1':
            int_choice = 1
            #Calls addition function on choice
            addition.addition()
            loop = True
        elif choice == '2':
            int_choice = 2
            #Calls subtraction function on choice
            subtraction.subtraction()
            loop = True
        elif choice == '3':
            int_choice = 3
            #Calls multiplication function on choice
            multiplication.multiplication()
            loop = True
        elif choice == '4':
            int_choice = 4
            #Calls devision function on choice
            division.division()
            loop = True
        elif choice == '5':
            int_choice = -1
            print("Exiting..")
            #Loop becomes False and exits the script
            loop = False
        else:
            #Any value other than 1-5 will validate as an error message to loop back to the menu
            input("Wrong menu selection. Enter any key to try again..")
    return [int_choice, choice]
Esempio n. 4
0
def importsubt():
    global a
    global b
    global c
    global display

    a,b,c,display= subtraction.subtraction(a,b,c,display)
    text_input.set(a)
Esempio n. 5
0
def calculator ():

    print("Welcome to Kuba's Calculator!")
    while True:
        print("Options to do: ")
        print("Enter 'add' to use addiction(+)")
        print("Enter 'subtract' to use subtraction(-)")
        print("Enter 'multiply' to use multiplication(X)")
        print("Enter ' divide' to use division(/)")
        print("Enter 'close' to end the program :(")
        result = input("Your choice?!: ")
        if result == "add":
            num1 = input("Enter first substrate of operation: ")
            num2 = input("Enter second substrate of operation: ")
            n1t = num1.isdigit()
            n2t = num2.isdigit()
            if n1t and n2t == True:
                    product = addition(num1, num2)
                    print("it's ", product, ", and again!")
                
            else:
                print("Enter again!")
                continue
        elif result == "subtract":
            num1 = input("Enter first substrate of operation: ")
            num2 = input("Enter second substrate of operation: ")
            n2t = num2.isdigit()
            if n1t and n2t == True:
                    product = subtraction(num1, num2)
                    print("It's ", product, ", and again!")
            else:
                print("Enter again!")
                continue
        elif result == "multiplication":
            num1 = input("Enter first substrate of operation: ")
            num2 = input("Enter second substrate of operation: ")
            n2t = num2.isdigit()
            if n1t and n2t == True:
                    product = multiplication(num1, num2)
                    print("It's ", product, ", and again!")
            else:
                print("Enter again!")
                continue
        elif result == "division":
            num1 = input("Enter first substrate of operation: ")
            num2 = input("Enter second substrate of operation: ")
            n2t = num2.isdigit()
            if n1t and n2t == True:
                    product = division(product)
                    print("It's ", product, ", and again!")
            else:
                print("Enter again!")
                continue
        elif result == "close":
            break
        else:
            print("Enter again!")
            continue
 def test_subtraction(self):
     a = random.randint(0, 100)
     b = random.randint(0, 100)
     self.assertEqual(subtraction.subtraction(a, b), a - b)
     print("a", "=", a)
     print("b", "=", b)
     if a > b:
         print(a, "-", b, "=", a - b)
     else:
         print(b, "-", a, "=", b - a)
Esempio n. 7
0
         break
     except ValueError:
         print("Необходимо ввести ЧИСЛО!")
         print("")
 print("")
 while True:
     sign = input(
         '''Нажмите кнопку, которая соответствует требуемому действию:
     1) +
     2) -
     3) *
     4) /
     :''')
     if sign in ['+', '-', '*', '/', '1', '2', '3', '4']:
         break
     else:
         print("Введите знак или цифру соответствующую знаку!")
         continue
 print("")
 if sign == '+' or sign == '1':
     from add import add
     add(value1, value2)
 elif sign == '-' or sign == '2':
     from subtraction import subtraction
     subtraction(value1, value2)
 elif sign == '*' or sign == '3':
     from multiply import multiply
     multiply(value1, value2)
 elif sign == '/' or sign == '4':
     from divide import divide
     divide(value1, value2)
Esempio n. 8
0
 def test_1(self):
     result = subtraction(5, 4)
     self.assertEqual(result, 1)
Esempio n. 9
0
 def test_3(self):
     result = subtraction(10, 15)
     self.assertEqual(result, -5)
Esempio n. 10
0
 def test_2(self):
     result = subtraction(-5, -10)
     self.assertEqual(result, 5)
Esempio n. 11
0
 def subtract(self, a, b):
     self.result = subtraction(a, b)
     return self.result
Esempio n. 12
0
 def subtract(self, a, b):
     a = int(a)
     b = int(b)
     self.result = subtraction(a, b)
     return self.result
Esempio n. 13
0
        while not second_operand.isdigit():
            if second_operand == 'exit':
                print('So, you want to loose. ok...')
                exit(0)
            else:
                is_minus = second_operand.replace('-', '')
                if not is_minus.isdigit():
                    print(second_operand)
                    second_operand = input(
                        'NO! Enter 2nd NUMBER as integer, pls:\n>')
                else:
                    break
        second_operand = int(second_operand)

        # equals
        if function_in == '+':
            equals = add.add(first_operand, second_operand)
        elif function_in == '-':
            equals = subtraction.subtraction(first_operand, second_operand)
        elif function_in == '*':
            equals = multiply.multiply(first_operand, second_operand)
        elif function_in == '/':
            equals = divide.divide(first_operand, second_operand)
        elif function_in == '//':
            equals = divide.int_divide(first_operand, second_operand)

        # result
        print(f'{first_operand} {function_in} {second_operand} =', equals)
    else:
        exit(0)