def execute(opCode, reg1, reg2):

    # Read registers
    registers = misc.readRegisters('registers.txt')
    if reg1 != " ":
        op1 = registers[int(reg1)]
    if reg1 != " ":
        op2 = registers[int(reg2)]

    if opCode.find("dadd") != -1:
        return calc.sum(op1, op2)
    elif opCode.find("daddi") != -1:
        return calc.daddi(op1, op2)
    elif opCode.find("dsub") != -1:
        return calc.sub(op1, op2)
    elif opCode.find("lw") != -1:
        return "LW"
    elif opCode.find("dsubi") != -1:
        return calc.sub(int(op1), int(op2))
    elif opCode.find("beqz") != -1:
        return calc.beqz(op1)
    elif opCode.find("bnez") != -1:
        return calc.bnez(op1)
    elif opCode.find("beq") != -1:
        return calc.beq(op1, op2)
    elif opCode.find("bne") != -1:
        return calc.bne(op1, op2)
    elif opCode.find("j") != -1:
        return "JUMP"
    elif opCode.find("   ") != -1:
        return 0
    else:
        #print("Wrong instruction - review code")
        return 1
 def test_sub(self):
     result = calculator.sub(10, 10)
     self.assertEqual(result, 0)
     result = calculator.sub(20, 10)
     self.assertEqual(result, 10)
     result = calculator.sub(30, 10)
     self.assertEqual(result, 20)
    def test_sub(self):
        res = calculator.sub(2, 2)
        self.assertEqual(res, 0)

        res = calculator.sub(6.2, 2.1)
        self.assertEqual(res, 4.1)

        res = calculator.sub(-3.2, 1.4)
        self.assertEqual(res, -4.6)
def main():
    """Tests a few calculator function calls"""

    adds_1_2 = add(1, 2)
    print("adds 1 + 2:", adds_1_2)

    subtracts_1_2 = sub(1, 2)
    print("subtracts 1 - 2:", subtracts_1_2)

    multiplies_1_2 = mul(1, 2)
    print("multiplies 1 * 2:", multiplies_1_2)

    divides_1_2 = div(1, 2)
    print("divides 1 * 2:", divides_1_2)
Esempio n. 5
0
def main():
    op = input("enter op.: +, -, *, /: ")
    num1 = int(input("enter a number: "))
    num2 = float(input("enter a decimal number: "))

    if op == "+":
        result = calculator.add(num1, num2)
    elif op == "-":
        result = calculator.sub(num1, num2)
    elif op == "*":
        result = calculator.mult(num1, num2)
    elif op == "/":
        result = calculator.div(num1, num2)
    else:
        print("Invalid operation")
    print(result)
def my_calc():
    # show intro text
    print('Calculator Program. Enter your mathematical expression below. '
          '\nEnter "help" for help and hit ENTER/RETURN to quit')
    # start while loop
    while True:
        cmd = input('> ')
        if cmd == "":
            break
        elif 'help' in cmd:
            print('DIRECTORY COMMANDS:')
            print('To add two numbers, enter: add')
            print('To subtract two numbers, enter: sub')
            print('To multiply two numbers, enter: mul')
            print('To divide two numbers, enter: div')
            print('To view calculator history, enter: history')
            print('To clear calculator history, enter: clear history')
            print('To quit, press enter')
            print(
                'Must type these command like so: command, space, number, space, number. i.e: div 10 2'
            )
        elif cmd == ('add'):
            cmd = cmd.split(" ")
            output = calculator.add(cmd[1], cmd[2])
            print(output)
        elif cmd == 'sub':
            cmd = cmd.split(" ")
            output = calculator.sub(cmd[1], cmd[2])
            print(output)
        elif cmd == 'mul':
            cmd = cmd.split(" ")
            output = calculator.mul(cmd[1], cmd[2])
            print(output)
        elif cmd == 'div':
            cmd = cmd.split(" ")
            output = calculator.div(cmd[1], cmd[2])
            print(output)
        elif cmd == 'clear history':
            calculator.clear_history()
            print("history cleared.")
        elif cmd == 'history':
            output = calculator.calc_history()
            print('Here is your calculator history:')
            print(output)
        else:
            print('Invalid command, please try again')
Esempio n. 7
0
# from calculator import add

# result = calculator.add(1,2)
# print(result)

#
# from calculator import add

# result = add(1,2)
# print(result)

#
from calculator import add,sub,mul,div
# from calculator import * #*는 모두를 지정함.
result = add(1,2)
print(result)
result = sub(7,3)
print(result)
result = mul(20,11)
print(result)
result = div(10,4)
print(result)
Esempio n. 8
0
from calculator import sum, sub
# import calculator
# print(calculator.sum(1,2))
print(sum(1,3))
print(sub(1,5))
print(abs(sub(1,5)))
 def test_sub(self):
     assert 2 == calculator.sub(4, 2)
Esempio n. 10
0
import calculator as cal

#ctrl + d 똑같은 키워드 순서대로 선택됨

num1 = cal.add(10, 2)
print(num1)

num2 = cal.sub(10, 2)
print(num2)

num3 = cal.mul(10, 2)
print(num3)

num4 = cal.div(10, 2)
print(num4)
Esempio n. 11
0
import calculator as cal

num1=cal.add(10,2)
print(num1)

num1=cal.sub(10,2)
print(num1)

num1=cal.mul(10,2)
print(num1)

num1=cal.div(10,2)
print(num1)
Esempio n. 12
0
import calculator as cal

x = int(input("Enter a Number"))
y = int(input("Enter a Number"))

z=cal.add(x, y)
q=cal.sub(x,y)
w=cal.div(x,y)
s=cal.mod(x,y)

print(z)
print(q)
print(w)
print(s)
 def test_fail(self):
     self.assertEqual(calculator.sub(2, 4), 0)
Esempio n. 14
0
File: main.py Progetto: Q3333/Study
import calculator

add_result = calculator.add(10, 2)
sub_result = calculator.sub(10, 2)
mul_result = calculator.mul(10, 2)
div_result = calculator.div(10, 2)
mod_result = calculator.mod(10, 2)

print(add_result)  #=> 12
print(sub_result)  #=> 8
print(mul_result)  #=> 20
print(div_result)  #=> 5
print(mod_result)  #=> 0
Esempio n. 15
0
import calculator

num1=calculator.add(10,2)
print(num1)

num2=calculator.sub(10,2)
print(num2)

num3=calculator.mul(10,2)
print(num3)

num4=calculator.div(10,2)
print(num4)
Esempio n. 16
0
import calculator as c

a = int(input("Enter the first number"))
b = int(input("Enter the second number "))
ch = 0
while ch != 6:
    print("MENU")
    print(
        "1.ADD \n 2.SUBTRACT\n 3.MULTIPLICATON \n 4.DIVISION \n 5.MODULUS \n 6.EXIT"
    )
    ch = int(input("enter your choice"))
    if (ch == 1):
        z = c.add(a, b)
        print(z)
    elif (ch == 2):
        z = c.sub(a, b)
        print(z)
    elif (ch == 3):
        z = c.mult(a, b)
        print(z)
    elif (ch == 4):
        z = c.div(a, b)
        print(z)
    elif (ch == 5):
        z = c.mod(a, b)
        print(z)
    elif (ch == 6):
        print("exit")
    else:
        print("Invalid Number")
            print('Here is your calculator history:')
            print(output)
        else:
            print('Invalid command, please try again')


if __name__ == '__main__':

    # just show the top 5 best roles
    counter = ygm_best_role()
    pprint(counter)
    pprint({role: count for role, count in counter.items() if count > 50})

    # just show the top 10 lines from a_new_hope_lines.txt
    sw_number_lines()
    try:
        print('\n')
        with open(os.path.join('scripts', 'a_new_hope_lines.txt'),
                  'r') as infile:
            pprint(infile.read().splitlines(False)[:10])
    except:
        # broad clause ok here while testing...just in case sw_number_lines() isn't written yet
        print('couldn\'t find "a_new_hope_lines.txt" in the "scripts" folder')

    # try out my calculator code
    calculator.add('4', '6')
    calculator.div('6', '3')
    calculator.mul('4', '5')
    calculator.sub('10', '4')
    my_calc()
Esempio n. 18
0
 def sub(self, m, n):
     return c.sub(m, n)
Esempio n. 19
0
import calculator

calculator.add()
calculator.sub()
calculator.mul()
 def test_sub(self):
     self.assertEqual(calculator.sub(40, 2), 38)
Esempio n. 21
0
 def test_calculator(self):
     self.assertEqual(calc.sum(2, 2), 4)
     self.assertEqual(calc.sub(2, 2), 0)
     self.assertEqual(calc.mul(2, 3), 6)
     self.assertEqual(calc.div(2, 2), 1)
Esempio n. 22
0
 def test_subtract(self):
     self.assertEqual(calculator.sub(10, 5), 5)
     self.assertEqual(calculator.sub(10, -5), 15)
     self.assertEqual(calculator.sub(-10, -5), -5)
Esempio n. 23
0
def double_return():
    return 3, 4, 5


result = double_return()

print(type(result), result)

result1 = (lambda x, y: x * y)(3, 4)

print(result1)

import calculator

print(calculator.add(3, 5))
print(calculator.sub(5, 3))

import sys

path_list = sys.path

for item in path_list:
    print(item)

inventory = {
    'gold': 500,
    'pouch': ['flint', 'twine',
              'gemstone'],  # Assigned a new list to 'pouch' key
    'backpack': ['xylophone', 'dagger', 'bedroll', 'bread loaf']
}
Esempio n. 24
0
import calculator

while True:
    print(
        "pls choose a option\n 1 : sum \n 2 : sub \n 3 : multiply \n 4 : divide"
    )

    options = input("What is your choice ?")
    if options == "1" or options == "2" or options == "3" or options == "4":
        break
    else:
        print("*** pls choose a correct option ***")
        continue

hm_numbers = int(input("How many numbers will you use ?"))
choosen = list(
    map(lambda nums: int(input('enter a number : ')),
        range(1, hm_numbers + 1)))  # I wanted to use disposable function.

if options == '1':
    print(calculator.sum(choosen))

elif options == '2':
    print(calculator.sub(choosen))

elif options == '3':
    print(calculator.multiply(choosen))

elif options == '4':
    print(calculator.divide(choosen))
 def test_sub(self):
     assert 9 == calculator.sub(10, 1)
Esempio n. 26
0
import calculator

print(calculator.add(2, 3))
print(calculator.sub(2, 3))
print(calculator.mul(2, 3))
print(calculator.div(2, 3))
Esempio n. 27
0
 def test_sub(self):
     self.assertEqual(calculator.sub(2, 3), -1)
Esempio n. 28
0
 def test_sub(self):
     assert 5 == calculator.sub(7,2)
Esempio n. 29
0
from calculator import add, sub

result = add(1, 2)
print(result)
result = sub(3 - 1)
print(result)
 def testSubtraction(self):
     ''''Calculator should return the difference of two numbers'''
     for num1, num2 in self.testValues:
         result = calculator.sub(num1, num2)
         self.assertEqual(3, result)
Esempio n. 31
0
# FIRST CREATE YOUR OWN MODULE --> e.g; calculator.py
# FIRST WAY OF IMPORTING OUR OWN MODULE
import calculator

print(calculator.add(2, 2))
print(calculator.sub(2, 2))
print(calculator.divide(2, 2))
print(calculator.multiply(2, 2))

# SECOND WAY OF IMPORTING WITH JUST BRINGING SPECIFIC METHODS
from calculator import add

print(add(2, 4))
Esempio n. 32
0
 def testSub(self):
     self.assertEqual(calculator.sub(2, 5), -3)
     self.assertEqual(calculator.sub(5, -2), 3)
     self.assertEqual(calculator.sub(-5, 5), -10)