Example #1
0
def method():
    while True:
        print("Welcome to the simple calculator in python")
        op = input("Enter the operator: ")
        thislist = []
        a = True

        while a == True:
            n1 = input("enter the number: ")
            print("To calculate type '=': ")
            if n1 == "=":
                a = False
            else:
                n1 = float(n1)
                thislist.append(n1)

        if op == "+":
            answer = addition.add(thislist)
            print("result: " + str(answer))
            print(thislist)
        elif op == "-":
            answer = subtraction.sub(thislist)
            print("result: " + str(answer))
        elif op == "*":
            answer = multiplication.mul(thislist)
            print("result: " + str(answer))
        elif op == "/":
            answer = division.div(thislist)
            print("result: " + str(answer))
        else:
            print("Invalid operator")

        print(" ")
Example #2
0
from add import add
from diff import subtract
from multiply import multi
from division import div
from modulus import mod

input1 = int(input("enter number 1: "))
input2 = int(input("enter number 2: "))

op = input("enter operator: ")

if op == '+':
    print("sum:", add(input1, input2))
elif op == '-':
    print("difference:", subtract(input1, input2))
elif op == '*':
    print("product:", multi(input1, input2))
elif op == '/':
    print("quotient:", div(input1, input2))
elif op == '%':
    print("modulus:", mod(input1, input2))
Example #3
0
from addition import add
from subtraction import sub 
from division import div
from multiple import mult

print ("Welcome to Calculator Function")
print ("Choose option from menu:")
print ("1. Add")
print ("2. Subtract")
print ("3. Multiply")
print ("4. Division")

choice = int(input("Enter choice (1/2/3/4): "))

num1 = float(input("Enter 1st number: "))
num2 = float(input("Enter 2nd number: "))

if(choice is 1):
    print (add(num1,num2))

if (choice is 2):
    print (sub(num1, num2))

if(choice is 3):
    print (mult(num1,num2))

if (choice is 4):
    print (div(num1,num2))
Example #4
0
from addition import add
from subtraction import sub
from multiplication import multi
from division import div
from modulo import mod

print ("a=6, b=4")

print ("sum:", add(6, 4))
print ("difference:", sub(6, 4))
print ("product:", multi(6, 4))
print ("quotient:", div(6, 4))
print ("remainder:", mod(6, 4))
#Menu file
import addition,subtract,multiplication,division,modulus



print("This program is for add,sub,mult and divide\n1.Addition\n2.Subtraction\n3.Multiplication\n4.Division\n5.Modulus")
s=int(input("Enter your choice:"))
if(s==1):
	print(addition.add())
elif(s==2):
	print(subtract.sub())
elif(s==3):
	print(multiplication.mult())
elif(s==4):
	print(division.div())
elif(s==5):
	print(modulus.mod())
else:
	print("Invalid input")	
Example #6
0
from addition import add
from subtraction import sub
from division import div
from multiple import mult

print("Welcome to Calculator Function")
print("Choose option from menu:")
print("1. Add")
print("2. Subtract")
print("3. Multiply")
print("4. Division")

choice = int(input("Enter choice (1/2/3/4): "))

num1 = float(input("Enter 1st number: "))
num2 = float(input("Enter 2nd number: "))

if (choice is 1):
    print(add(num1, num2))

if (choice is 2):
    print(sub(num1, num2))

if (choice is 3):
    print(mult(num1, num2))

if (choice is 4):
    print(div(num1, num2))
Example #7
0
import addition
import substraction
import multiplication
import division

a = int(input('Enter first number : '))
b = int(input('Enter second number : '))
op = input('Enter the operator : ')

if op == '+':
    print(addition.add(a, b))
elif op == '-':
    print(substraction.sub(a, b))
elif op == '*':
    print(multiplication.multiply(a, b))
elif op == '/':
    print(division.div(a, b))
else:
    print('Invalid operator')

Example #8
0
import argparse
import division

# Initialize parser
parser = argparse.ArgumentParser(
    description="Multiply A and B with Booth's Algorithm")

# Define args
parser.add_argument("-A", type=int, required=True, help="dividend")
parser.add_argument("-B", type=int, required=True, help="divisor")
parser.add_argument("--s",
                    dest="s",
                    action='store_true',
                    help="flag to save instead of print to console")

# Read args
args = parser.parse_args()
A = args.A  #multiplicand
B = args.B  #multiplier

n = max([A.bit_length(), B.bit_length()])

value = division.div(A, B, n)

if args.s:
    f = open("saved.txt", "w")
    f.write(value)
    f.close()
else:
    print(value)
Example #9
0
 def test_div(self):
     self.assertEqual(div(7, 3), 7 // 3)
import summation
import subtraction
import multiplication
import division
a=int(raw_input("enter the first number : "))
b=int(raw_input("enter the second number : "))
summation.add(a,b)
subtraction.sub(a,b)
multiplication.mult(a,b)
division.div(a,b)