Beispiel #1
0
#!/usr/bin/python3
if __name__ == "__main__":
    from calculator_1 import add, sub, mul, div
    a = 10
    b = 5
    print("{} + {} = {}".format(a, b, add(a, b)), end="\n")
    print("{} - {} = {}".format(a, b, sub(a, b)), end="\n")
    print("{} * {} = {}".format(a, b, mul(a, b)), end="\n")
    print("{} / {} = {}".format(a, b, div(a, b)), end="\n")
#!/usr/bin/python3
if __name__ == "__main__":
    from calculator_1 import add, sub, mul, div
    a = 10
    b = 5
    print('{:d} + {:d} = {:d}'.format(a, b, add(a, b)))
    print('{:d} - {:d} = {:d}'.format(a, b, sub(a, b)))
    print('{:d} * {:d} = {:d}'.format(a, b, mul(a, b)))
    print('{:d} / {:d} = {:d}'.format(a, b, div(a, b)))
#!/usr/bin/python3
from calculator_1 import add, mul, sub, div

# Import guard
if __name__ == '__main__':
    a = 10
    b = 5
    print("{:d} + {:d} = {:d}".format(a, b, add(a, b)))
    print("{:d} - {:d} = {:d}".format(a, b, sub(a, b)))
    print("{:d} * {:d} = {:d}".format(a, b, mul(a, b)))
    print("{:d} / {:d} = {:d}".format(a, b, div(a, b)))
Beispiel #4
0
#!/usr/bin/python3
if __name__ == "__main__":
    from calculator_1 import add, sub, mul, div
    from sys import argv
    if len(argv) != 4:
        print("Usage: ./100-my_calculator.py <a> <operator> <b>")
        exit(1)
    else:
        op = argv[2]
        if op != "+" and op != "-" and op != "*" and op != "/":
            print("Unknown operator. Available operators: +, -, * and /")
            exit(1)
        else:
            a = argv[1]
            b = argv[3]
            ai = int(a, 10)
            bi = int(b, 10)
            if argv[2] is "+":
                res = add(ai, bi)
            elif argv[2] is "-":
                res = sub(ai, bi)
            elif argv[2] is "*":
                res = mul(ai, bi)
            elif argv[2] is "/":
                res = div(ai, bi)
            print("{:d} {} {:d} = {:d}".format(ai, argv[2], bi, res))
#!/usr/bin/python3
if __name__ == "__main__":
    a = 10
    b = 5
    import calculator_1 as cal
    print('{} + {} = {}'.format(a, b, cal.add(int(a), int(b))))
    print('{} - {} = {}'.format(a, b, cal.sub(int(a), int(b))))
    print('{} * {} = {}'.format(a, b, cal.mul(int(a), int(b))))
    print('{} / {} = {}'.format(a, b, cal.div(int(a), int(b))))
Beispiel #6
0
#!/usr/bin/python3
from calculator_1 import add, sub, mul, div
from sys import argv, exit
if __name__ == "__main__":
    if len(argv) != 4:
        print("Usage: ./100-my_calculator.py <a> <operator> <b>")
        exit(1)
    if argv[2] != "+" and argv[2] != "-" and argv[2] != "*" and argv[2] != "/":
        print("Unknown operator. Available operators: +, -, * and /")
        exit(1)
    a = int(argv[1])
    b = int(argv[3])
    if argv[2] == "+":
        calc = add(a, b)
    if argv[2] == "-":
        calc = sub(a, b)
    if argv[2] == "*":
        calc = mul(a, b)
    if argv[2] == "/":
        calc = div(a, b)
    print("{} {} {} = {}".format(a, argv[2], b, calc))
#!/usr/bin/python3
if __name__ == "__main__":
    import sys
    argv = sys.argv
    from calculator_1 import add, sub, mul, div
    l = len(argv)
    if l != 4:
        print("Usage: ./100-my_calculator.py <a> <operator> <b>")
        sys.exit(1)
    if argv[2] not in "+-*/":
        print("Unknown operator. Available operators: +, -, * and /")
        sys.exit(1)
    a = int(argv[1])
    b = int(argv[3])
    if argv[2] == "+":
        print("{} {} {} = {}".format(a, argv[2], b, add(a, b)))
    elif argv[2] == "-":
        print("{} {} {} = {}".format(a, argv[2], b, sub(a, b)))
    elif argv[2] == "*":
        print("{} {} {} = {}".format(a, argv[2], b, mul(a, b)))
    else:
        print("{} {} {} = {}".format(a, argv[2], b, div(a, b)))
#!/usr/bin/python3
if __name__ == "__main__":
    from calculator_1 import add, sub, mul, div
    import sys
    n = len(sys.argv) - 1
    if n != 3:
        print("Usage: ./100-my_calculator.py <a> <operator> <b>")
        exit(1)
    else:
        i = 0
        a = int(sys.argv[i + 1])
        op = sys.argv[i + 2]
        b = int(sys.argv[i + 3])
        if op is "+":
            c = add(a, b)
        elif op is "-":
            c = sub(a, b)
        elif op is "*":
            c = mul(a, b)
        elif op is "/":
            c = div(a, b)
        else:
            print("Unknown operator. Available operators: +, -, * and /")
            exit(1)
        print("{} {} {} = {}".format(a, op, b, c))
        exit(0)
#!/usr/bin/python3
from sys import argv
from calculator_1 import add, sub, mul, div
if __name__ == '__main__':
    arguments = len(argv)
    if arguments is not 4:
        print("Usage:", argv[0], '<a> <operator> <b>')
        exit(1)

    num1 = int(argv[1])
    operator = argv[2]
    num2 = int(argv[3])

    if operator is '+':
        numE = add(num1, num2)

    elif operator is '-':
        numE = sub(num1, num2)

    elif operator is '*':
        numE = mul(num1, num2)

    elif operator is '/':
        numE = div(num1, num2)

    else:
        print("Unknown operator. Available operators: +, -, * and /")
        exit(1)
    print("{:d} {} {:d} = {:d}".format(num1, operator, num2, numE))
Beispiel #10
0
 def my_sub():
     auxSub = sub(a, b)
     print("{:d} - {:d} = {:d}".format(a, b, auxSub))
     return auxSub
Beispiel #11
0
#!/usr/bin/python3
from calculator_1 import add, sub, mul, div
from sys import argv, exit
if __name__ == "__main__":
    operators = {'+', '-', '*', '/'}

    if len(argv) != 4:
        print("Usage: ./100-my_calculator.py <a> <operator> <b>")
        exit(1)
    if not argv[2] in operators:
        print("Unknown operator. Available operators: +, -, * and /")
        exit(1)
    else:
        a = int(argv[1])
        b = int(argv[3])
        if argv[2] == '+':
            print("{:d} {} {:d} = {:d}".format(a, argv[2], b, add(a, b)))
        if argv[2] == '-':
            print("{:d} {} {:d} = {:d}".format(a, argv[2], b, sub(a, b)))
        if argv[2] == '*':
            print("{:d} {} {:d} = {:d}".format(a, argv[2], b, mul(a, b)))
        if argv[2] == '/':
            print("{:d} {} {:d} = {:d}".format(a, argv[2], b, div(a, b)))
Beispiel #12
0
#!/usr/bin/python3
if __name__ == "__main__":
    import calculator_1 as calcu
    a = 10
    b = 5
    print("{} + {} = {}".format(a, b, calcu.add(a, b)))
    print("{} - {} = {}".format(a, b, calcu.sub(a, b)))
    print("{} * {} = {}".format(a, b, calcu.mul(a, b)))
    print("{} / {} = {}".format(a, b, calcu.div(a, b)))
#!/usr/bin/python3
if __name__ == '__main__':
    from calculator_1 import add, sub, mul, div
    a = 10
    b = 5
    print("""{0} + {1} = {2}
{0} - {1} = {3}
{0} * {1} = {4}
{0} / {1} = {5}
""".format(a, b, add(a, b), sub(a, b), mul(a, b), div(a, b)),
          end='')
#!/usr/bin/python3
if __name__ == "__main__":
    from calculator_1 import add, sub, mul, div
    from sys import argv
    args = len(argv)

    if args != 4:
        print("Usage: ./100-my_calculator.py <a> <operator> <b>")
        exit(1)
    else:
        a = int(argv[1])
        b = int(argv[3])
        add = add(a, b)
        sub = sub(a, b)
        mul = mul(a, b)
        div = div(a, b)
        if argv[2] == '+':
            print("{} + {} = {}".format(a, b, add))
        elif argv[2] == '-':
            print("{} - {} = {}".format(a, b, sub))
        elif argv[2] == '*':
            print("{} * {} = {}".format(a, b, mul))
        elif argv[2] == '/':
            print("{} / {} = {}".format(a, b, div))
        else:
            print("Unknown operator. Available operators: +, -, * and /")
            exit(1)
    import sys
    import calculator_1
    str1 = "Usage: ./100-my_calculator.py <a> <operator> <b>"
    str2 = "Unknown operator. Available operators: +, -, * and /"
    num = (len(sys.argv))

    if num != 4:
        print("{}".format(str1))
        exit(1)

    if sys.argv[2] not in "+-*/":
        print("{}".format(str2))
        exit(1)

    a = int(sys.argv[1])
    b = int(sys.argv[3])

    if sys.argv[2] == "+":
        result = calculator_1.add(a, b)

    if sys.argv[2] == "-":
        result = calculator_1.sub(a, b)

    if sys.argv[2] == "*":
        result = calculator_1.mul(a, b)

    if sys.argv[2] == "/":
        result = calculator_1.div(a, b)

    print("{:d} {} {:d} = {:d}".format(a, sys.argv[2], b, result))
 def my_sub():
     total = sub(num1, num2)
     print("{:d} - {:d} = {:d}".format(num1, num2, total))
     return total
Beispiel #17
0
#!/usr/bin/python3
if __name__ == "__main__":
    from calculator_1 import add, sub, mul, div
    a = 10
    b = 5
    print("{0:d} + {1:d} = {2:d}".format(a, b, add(a, b)))
    print("{0:d} - {1:d} = {2:d}".format(a, b, sub(a, b)))
    print("{0:d} * {1:d} = {2:d}".format(a, b, mul(a, b)))
    print("{0:d} / {1:d} = {2:d}".format(a, b, div(a, b)))
Beispiel #18
0
#!/usr/bin/python3
if __name__ == '__main__':
    from calculator_1 import add, sub, mul, div

    a = 10
    b = 5

print('{} + {} = {}'.format(a, b, add(a, b)))
print('{} - {} = {}'.format(a, b, sub(a, b)))
print('{} * {} = {}'.format(a, b, mul(a, b)))
print('{} / {} = {}'.format(a, b, div(a, b)))
#!/usr/bin/python3
if __name__ == "__main__":
    import sys
    from calculator_1 import add, sub, mul, div
    if len(sys.argv) != 4:
        print("Usage: ./100-my_calculator.py <a> <operator> <b>")
        exit(1)

    op = "+-*/"
    if sys.argv[2] not in op:
        print("Unknown operator. Available operators: +, -, * and /")
        exit(1)
    print("{} {} {} = ".format(sys.argv[1], sys.argv[2], sys.argv[3]), end="")
    ope = sys.argv[2]
    a = int(sys.argv[1])
    b = int(sys.argv[3])
    if ope == '+':
        print("{}".format(add(a, b)))
    elif ope == '-':
        print("{}".format(sub(a, b)))
    elif ope == '*':
        print("{}".format(mul(a, b)))
    else:
        print("{}".format(div(a, b)))
    The program will execute an operation between two numbers
    selected by the operator sent to the program.
    """
    l_av = len(argv) - 1

    if l_av == 3:
        operator = argv[2]
        num_a = int(argv[1])
        num_b = int(argv[3])
        if operator == '+':
            res = add(num_a, num_b)
            print('{:d} + {:d} = {:d}'.format(num_a, num_b, res))
            exit(0)
        elif operator == '-':
            res = sub(num_a, num_b)
            print('{:d} - {:d} = {:d}'.format(num_a, num_b, res))
            exit(0)
        elif operator == '*':
            res = mul(num_a, num_b)
            print('{:d} * {:d} = {:d}'.format(num_a, num_b, res))
            exit(0)
        elif operator == '/':
            res = div(num_a, num_b)
            print('{:d} / {:d} = {:d}'.format(num_a, num_b, res))
            exit(0)
        else:
            print('Unknown operator. Available operators: +, -, * and /')
            exit(1)
    else:
        print('Usage: ./100-my_calculator.py <a> <operator> <b>')
Beispiel #21
0
#!/usr/bin/python3
if __name__ == "__main__":
    from sys import argv
    from calculator_1 import add, sub, mul, div
    length = len(argv)
    if length != 4:
        print("Usage: ./100-my_calculator.py <a> <operator> <b>")
        exit(1)
    else:
        a = int(argv[1])
        b = int(argv[3])
        if argv[2] == '+':
            print("{} + {} = {}".
                  format(a, b, add(a, b)))
        elif argv[2] == '-':
            print("{} - {} = {}".
                  format(a, b, sub(a, b)))
        elif argv[2] == '*':
            print("{} * {} = {}".
                  format(a, b, mul(a, b)))
        elif argv[2] == '/':
            print("{} / {} = {}".
                  format(a, b, div(a, b)))
        else:
            print("Unknown operator. Available operators: +, -, * and /")
            exit(1)
Beispiel #22
0
#!/usr/bin/python3
from calculator_1 import add, sub, mul, div
from sys import argv

argv = argv[1:]
argc = len(argv)

if __name__ == "__main__":
    if argc != 3:
        print('Usage: ./100-my_calculator.py <a> <operator> <b>')
        exit(1)

    a = int(argv[0])
    b = int(argv[2])

    op = argv[1]

    if op == '+':
        res = add(a, b)
    elif op == '-':
        res = sub(a, b)
    elif op == '*':
        res = mul(a, b)
    elif op == '/':
        res = div(a, b)
    else:
        print('Unknown operator. Available operators: +, -, * and /')
        exit(1)

    print('{} {} {} = {}'.format(a, op, b, res))
Beispiel #23
0
#!/usr/bin/python3
if __name__ == "__main__":
    from sys import argv
    from calculator_1 import add, sub, mul, div
    l = len(argv)
    r = 0
    if l != 4:
        print('Usage: ./100-my_calculator.py <a> <operator> <b>')
        exit(1)
    else:
        a = int(argv[1])
        b = int(argv[3])
        if argv[2] == '+':
            r = add(a, b)
            print('{:d} + {:d} = {:d}'.format(a, b, r))
        elif argv[2] == '-':
            r = sub(a, b)
            print('{:d} - {:d} = {:d}'.format(a, b, r))
        elif argv[2] == '*':
            r = mul(a, b)
            print('{:d} * {:d} = {:d}'.format(a, b, r))
        elif argv[2] == '/':
            r = div(a, b)
            print('{:d} / {:d} = {:d}'.format(a, b, r))
        else:
            print('Unknown operator. Available operators: +, -, * and /')
            exit(1)
if __name__ == "__main__":
    from calculator_1 import add, sub, mul, div
    import sys

    if len(sys.argv) is not 4:
        print('Usage: ./100-my_calculator.py <a> <operator> <b>')
        sys.exit(1)

    elif (sys.argv[2] is not "+"\
         and sys.argv[2] is not "-"\
         and sys.argv[2] is not "*"\
         and sys.argv[2] is not "/"):
        print('Unknown operator. Available operators: +, -, * and /')
        sys.exit(1)

    elif sys.argv[2] == '+':
        print("{} + {} = {}".format(sys.argv[1], sys.argv[3],
                                    add(int(sys.argv[1]), int(sys.argv[3]))))

    elif sys.argv[2] == '-':
        print("{} - {} = {}".format(sys.argv[1], sys.argv[3],
                                    sub(int(sys.argv[1]), int(sys.argv[3]))))

    elif sys.argv[2] == '*':
        print("{} * {} = {}".format(sys.argv[1], sys.argv[3],
                                    mul(int(sys.argv[1]), int(sys.argv[3]))))

    elif sys.argv[2] == '/':
        print("{} / {} = {}".format(sys.argv[1], sys.argv[3],
                                    div(int(sys.argv[1]), int(sys.argv[3]))))
Beispiel #25
0
#!/usr/bin/python3
if __name__ == "__main__":
    from calculator_1 import add, sub, mul, div
    a = 10
    b = 5
    print("{} + {} = {}".format(a, b, add(a, b)))
    print("{} - {} = {}".format(a, b, sub(a, b)))
    print("{} * {} = {}".format(a, b, mul(a, b)))
    print("{} / {} = {}".format(a, b, div(a, b)))
Beispiel #26
0
#!/usr/bin/python3
from calculator_1 import add, sub, mul, div
from sys import argv
if __name__ == "__main__":
    l = len(argv)
    if l != 4:
        print("Usage: ./100-my_calculator.py <a> <operator> <b>")
        exit(1)
    op = argv[2]
    if op != '-' and op != '+' and op != '*' and op != '/':
        print("Unknown operator. Available operators: +, -, * and /")
        exit(1)
    a = int(argv[1])
    b = int(argv[3])
    if op == '+':
        print("{} {} {} = {}".format(a, op, b, add(a, b)))
    elif op == '-':
        print("{} {} {} = {}".format(a, op, b, sub(a, b)))
    elif op == '/':
        print("{} {} {} = {}".format(a, op, b, div(a, b)))
    else:
        print("{} {} {} = {}".format(a, op, b, mul(a, b)))
#!/usr/bin/python3

if __name__ == '__main__':
    from calculator_1 import add, sub, mul, div
    import sys as s
    operators = '+-*/'
    if (len(s.argv) is 4 and (s.argv[2] in operators)):
        op1 = int(s.argv[1])
        op2 = int(s.argv[3])
        if (operators[0] is s.argv[2]):
            print('{:d} + {:d} = {:d}'.format(op1, op2, add(op1, op2)))
        if (operators[1] is s.argv[2]):
            print('{:d} - {:d} = {:d}'.format(op1, op2, sub(op1, op2)))
        if (operators[2] is s.argv[2]):
            print('{:d} * {:d} = {:d}'.format(op1, op2, mul(op1, op2)))
        if (operators[3] is s.argv[2]):
            print('{:d} / {:d} = {:d}'.format(op1, op2, div(op1, op2)))
    else:
        if (len(s.argv) is 4):
            print('Unknown operator. Available operators: +, -, * and /')
        else:
            print('Usage: {} <a> <operator> <b>'.format(s.argv[0]))
        exit(1)
#!/usr/bin/python3
if __name__ == "__main__":
    import sys
    from calculator_1 import add, sub, mul, div

    args = sys.argv
    length = len(sys.argv)

    if length != 4:
        print("Usage: {} <a> <operator> <b>".format(args[0]))
        exit(1)
    elif args[2] == "+" or args[2] == "-" or args[2] == "*" or args[2] == "/":
        num1 = int(args[1])
        num2 = int(args[3])
        if args[2] == "+":
            print("{:d} + {:d} = {:d}".format(num1, num2, add(num1, num2)))
        elif args[2] == "-":
            print("{:d} - {:d} = {:d}".format(num1, num2, sub(num1, num2)))
        elif args[2] == "*":
            print("{:d} * {:d} = {:d}".format(num1, num2, mul(num1, num2)))
        elif args[2] == "/":
            print("{:d} / {:d} = {:d}".format(num1, num2, div(num1, num2)))
    else:
        print("Unknown operator. Available operators: +, -, * and /")
        exit(1)
Beispiel #29
0
if __name__ == "_main__":
    from calculator_1 import add, sub, mul, div
    from sys import argv
    ac = len(argv)
    if ac != 3:
        print("Usage: ./100-my_calculator.py <a> <operator> <b>")
        exit(1)
    a = int(argv[1])
    operator = int(argv[2])
    b = int(argv[3])
    if operator != '+':
        result = add(a, b)
    elif operator != '-':
        result = sub(a, b)
    elif operator != '*':
        result = mul(a, b)
    elif operator != '/':
        result = div(a, b)
    else:
        print("Unknown operator. Available operators: +, -, * and /")
    print("{:d} {} {:d} = {:d}".format(a, operator, b, result))
Beispiel #30
0
#!/usr/bin/python3
if __name__ == "__main__":
    from calculator_1 import add, sub, mul, div
    a = 10
    b = 5

    print("{} + {} = {}".format(a, b, add(a, b), end=''))
    print("{} - {} = {}".format(a, b, sub(a, b), end=''))
    print("{} * {} = {}".format(a, b, mul(a, b), end=''))
    print("{} / {} = {}".format(a, b, div(a, b), end=''))