def calculate():
    num1 = float(input("First Number:\n"))
    operator = str(input("Operator (+, -, *, /):\n"))
    num2 = float(input("Second Number:\n"))

    out = None

    if operator == "+":
        out = sum(num1, num2)
    elif operator == "-":
        out = subtract(num1, num2)
    elif operator == "*":
        out = multiply(num1, num2)
    elif operator == "/":
        out = divide(num1, num2)

    print("Resposta: " + str(out))
Esempio n. 2
0
def main():
  poll = None
  while(poll != "quit"):
    print("What would you like to do? (add, subtract, multiply, divide, quit)")  
    poll = input('>')

    if poll == "add":
      print("Your result is: %d\n\n" % (functions.add(*get_input())))

    elif poll == "divide":
      print("Your result is: %d\n\n" % (functions.divide(*get_input())))

    elif poll == "multiply":
      print("Your result is: %d\n\n" % (functions.multiply(*get_input())))

    elif poll == "subtract":
      print("Your result is: %d\n\n" % (functions.subtract(*get_input())))

    else:
      if not poll == "quit":
        print("Sorry, I didn't understand.")
def test_subtract():
    assert f.subtract(9, 3) == 6
    assert f.subtract(-1, -9) == 8
    assert f.subtract(-2, 2) == -4
    assert f.subtract(9, 8, in_order=False) == -1
        - To quit, press X
        """)

    op = input("> Enter operator key: ").lower()

    if op == 'x':
        break

    elif op == 'a':
        print("> The answer is: ", f.add(num1, num2))

    elif op == 's':
        in_order = bool(
            int(input(
                ">> Enter 1 -> num1 - num2 OR Enter 0 -> num2 - num1: ")))
        print("> The answer is: ", f.subtract(num1, num2, in_order=in_order))

    elif op == 'm':
        print("> The answer is: ", f.multiply(num1, num2))

    elif op == 'd':
        in_order = bool(
            int(input(">> Enter 1 -> num1 / num2 OR Enter 0 -> num2 / num1")))
        print("> The answer is: ", f.divide(num1, num2, in_order=in_order))

    elif op == 'p':
        print("> The answer is: ", f.power(num1, num2))

    else:
        print("> Invalid entry, try again...")
Esempio n. 5
0
def test_check_wrong_subtract():
    assert subtract(7, 2) == 3
Esempio n. 6
0
def test_check_subtract():
    assert subtract(5, 2) == 3
 def test_subtract(self):
     self.assertEqual(subtract(10, 5), 5)
     self.assertEqual(subtract(-1, 1), -2)
     self.assertEqual(subtract(-1, -1), 0)
Esempio n. 8
0
def tes_subtractNumbers():
    assert functions.subtract(6, 4) == 2
    return
Esempio n. 9
0
from functions.add import *
from functions.subtract import *
from functions.multiply import *
from functions.divide import *

numbers = [int(i) for i in input('Enter numbers seperated by comma').split(',')]

print ('Sum is %f' % (add(numbers[0], numbers[1])))
print ('Difference is %f' % (subtract(numbers[0], numbers[1])))
print ('Product is %f' % (multiply(numbers[0], numbers[1])))
print ('Division result is %f' % (divide(numbers[0], numbers[1])))
Esempio n. 10
0
def askUserForNumber():
    global numberOne, numberTwo
    numberOne = int(input("Podaj pierwszą liczbę "))
    numberTwo = int(input("Podaj drugą liczbę "))

choice = userChoice()

while choice != 5:
    if choice == 1:
        askUserForNumber()
        resultSum = functions.sum(numberOne, numberTwo)
        print("Wynik dodawania jest równy ", resultSum)
    elif choice == 2:
        askUserForNumber()
        resultSubtract = functions.subtract(numberOne, numberTwo)
        print("Wynik odejmowania jest równy", resultSubtract)
    elif choice == 3:
        askUserForNumber()
        while numberTwo ==0:
            print("Pamiętaj nie dziel przez 0!")
            askUserForNumber()
        resultDevsion = functions.divide(numberOne, numberTwo)
        print("Wynik dzielnia jest równy", resultDevsion)
    elif choice == 4:
        askUserForNumber()
        resultMultiply = functions.multiply(numberOne, numberTwo)
        print("Wynik mnożenia jest równy", resultMultiply)
    choice = userChoice()

print("Koniec programu")
Esempio n. 11
0
logger._srcFile = None
logger.logThreads = 0
logger.logProcesses = 0

fh = logging.FileHandler('log\{}.log'.format(datetime.datetime.now().strftime('%Y%m%d_%H%M%S')))
fh.setLevel(logging.DEBUG)

ch = logging.StreamHandler()
ch.setLevel(logging.WARNING)

fh_formatter = logging.Formatter('%(asctime)s - %(filename)s:%(lineno)s [%(levelname)s] %(message)s')
fh.setFormatter(fh_formatter)
ch_formatter = logging.Formatter('%(filename)s:%(lineno)s [%(levelname)s] %(message)s')
ch.setFormatter(ch_formatter)

logger.addHandler(fh)
logger.addHandler(ch)

####################################

num1 = 40
num2 = 0
logger.debug('Assigned values num1={} and num2={}'.format(num1, num2))

print(functions.add(num1, num2))
print(functions.subtract('error', num2))
print(functions.multiply(num1, num2))
print(functions.divide(num1, num2))

logger.debug('End of main.py')
Esempio n. 12
0
def step_impl(context, num1, num2):
    print(u'PASSO: When I input "{} - {}"  to calculator'.format(num1, num2))
    context.total = subtract(float(num1), float(num2))
Esempio n. 13
0
print("     1、相加")
print("     2、相减")
print("     3、相乘")
print("     4、相除")
print("########################  v1.0  ########################")

choice = int(input("请输入您的选择(1/2/3/4)"))

#判断选择是否正确
if choice != 1 and choice != 2 and choice != 3 and choice != 4:
    print("您的选择有误,请重新选择!")
    choice = int(input("请输入您的选择(1/2/3/4)"))

num1 = int(input("请输入第一个数字: "))
num2 = int(input("请输入第二个数字: "))

if choice == 1:
    print(num1, "+", num2, "=", functions.add(num1, num2))

if choice == 2:
    print(num1, "-", num2, "=", functions.subtract(num1, num2))

if choice == 3:
    print(num1, "*", num2, "=", functions.multiply(num1, num2))

if choice == 4:
    if num2 == 0:
        print("除数不能为零!")
    else:
        print(num1, "/", num2, "=", functions.divide(num1, num2))
Esempio n. 14
0
def test_skip():
    assert functions.subtract(9, 3) == 6
Esempio n. 15
0
import functions
from functions import subtract
from maths.multiplication import multiplication

if __name__ == '__main__':

    c = functions.add(10, 2)
    print(c)

    d = subtract(20, 10)
    print(d)

    e = multiplication(12, 10)
    print(e)
Esempio n. 16
0
 def test_subtract_ints(self):
     self.assertEqual(subtract(20, 3), 17)
Esempio n. 17
0
 def test_subtract(self):
     result = functions.subtract(100, 5)
     self.assertEqual(result, 95)
Esempio n. 18
0
    analog2Range = functions.getRange(
        functions.convertToFloat(functions.columnList(path + file, 1)))
    rangeList1.append(analog1Range)
    rangeList2.append(analog2Range)
    analog1Mean = functions.mean(
        functions.convertToFloat(functions.columnList(path + file, 0)))
    analog2Mean = functions.mean(
        functions.convertToFloat(functions.columnList(path + file, 1)))
    meanList1.append(analog1Mean)
    meanList2.append(analog2Mean)
    print("File: " + file)

#print(functions.sort(csv_files))
#print(rangeList1)
#print(rangeList2)

difference_mean = functions.subtract(meanList1, meanList2)
difference_range = functions.subtract(rangeList1, rangeList2)
divide_mean = functions.divide(meanList2, meanList1)
divide_range = functions.divide(rangeList1, rangeList2)

#print(divide_mean)

plt.plot(frequency, divide_mean, linestyle='-')
plt.axis([0, 5000, 0.5, 1])
#plt.errorbar(frequency, divide_mean, yerr = 0.05, fmt='o')
#plt.title('Hexagonal Prism Trial 1 Vibration Absorption Spectrum')
plt.ylabel('Proportion of Incoming Noise to Outgoing Noise Energy (%)')
plt.xlabel('Frequency (Hz)')
plt.show()