コード例 #1
0
    def test_divide(self):
        self.assertEqual(2, functions.divide(2, 1))
        # two different options to test Exceptions
        #using context manager
        with self.assertRaises(ValueError):
            functions.divide(5, 0)

        #other option using assertRaises and pass the arguments to it.
        self.assertRaises(ValueError, functions.divide, 5, 0)
コード例 #2
0
 def test_divide_negative(self):
     dividend = 15
     divisor = -3
     expected_result = -5.0
     self.assertAlmostEqual(divide(dividend, divisor),
                            expected_result,
                            delta=0.001)
コード例 #3
0
 def test_divide_result(self):
     dividend = 15
     divisor = 3
     expected_result = 5.0
     self.assertAlmostEqual(divide(dividend, divisor),
                            expected_result,
                            delta=0.0001)
コード例 #4
0
 def test_divide(self):
     self.assertEqual(divide(10, 5), 2)
     self.assertEqual(divide(-1, 1), -1)
     self.assertEqual(divide(-1, -1), 1)
     self.assertEqual(divide(5, 10), 0.5)
     with self.assertRaises(ValueError):
         divide(10, 0)
コード例 #5
0
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))
コード例 #6
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.")
コード例 #7
0
 def test_divide_error_on_zero(self):
     self.assertRaises(ValueError, lambda: divide(25, 0))
コード例 #8
0
    def test_divide(self):
        self.assertEqual(functions.divide(100, 2), 50)

        with self.assertRaises(ValueError):
            functions.divide(100, 0)
コード例 #9
0
 def test_divide_error_on_zero(self):
     with self.assertRaises(ValueError):
         divide(25, 0)
コード例 #10
0
 def test_divide_result(self):
     dividend = 15
     divisor = 3
     expected_result = 5.0
     # self.assertEqual(divide(dividend, divisor), expected_result)
     self.assertAlmostEqual(divide(dividend, divisor), expected_result, delta=0.0001) # this is recommended for testing divisions
コード例 #11
0
def test_divide():
    assert f.divide(8, 4) == 2
    assert f.divide(-2, 2) == -1
    assert f.divide(-5, -2) == 2.5
    assert f.divide(2, 5, in_order=False) == 2.5
コード例 #12
0
        - 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...")
コード例 #13
0
import functions
from functions import add_number

first_number = int(input("Enter the first number"))
second_number = int(input("Enter the second number"))

operation = input("Enter the operation(+,*,/)")

if operation == "+":
    print(f'Sum is : {add_number(first_number,second_number)}')
elif operation == "/":
    print("Divisor is :", functions.divide(first_number, second_number))
elif operation == "*":
    print("Product is :", functions.multiply_number(first_number,
                                                    second_number))
else:
    print("Please enter a valid operation")
コード例 #14
0
ファイル: test.py プロジェクト: kaustavsenkvs/Travis-
def test_check_divide():
    assert divide(5, 2) == 2.5
コード例 #15
0
 def test_divide_dividend_zero(self):
     dividend = 0
     divisor = 5
     expected_result = 0
     self.assertEqual(divide(dividend, divisor), expected_result)
コード例 #16
0
ファイル: main.py プロジェクト: DarrenAc/dac2
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))
コード例 #17
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')
コード例 #18
0
ファイル: test_functions.py プロジェクト: sw1203/Python_Udemy
 def test_divide_result(self):
     dividend = 15
     divisor = 3
     expected_result = 5.0
     self.assertEqual(divide(dividend, divisor), expected_result)  # 두 개의 값이 같은지를 확인
コード例 #19
0
ファイル: main.py プロジェクト: pragya-datt/labPrac
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])))
コード例 #20
0
import functions

for i in range(0, 1000000):
    functions.addition(1, 2)

for i in range(0, 1000000):
    functions.subtraction(2, 1)

for i in range(0, 1000000):
    functions.divide(1, 1)

lst = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j']
for i in range(0, 1000000):
    functions.iterate('z', lst)
コード例 #21
0
ファイル: main.py プロジェクト: wslusarczyk/simple-calculator
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")
コード例 #22
0
 def test_divide_dividend_zero(self):
     dividend = 0
     divider = 5
     expected_result = 0
     self.assertAlmostEquals(divide(dividend, divider), expected_result)
コード例 #23
0
ファイル: main.py プロジェクト: deadeyesky/WaveFunction-test
    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()