def printResult(op1, op2): if menunumber == "1": print("\t\t", op1, "+", op2, "=", calculator.plus(op1, op2)) elif menunumber == "2": print("\t\t", op1, "-", op2, "=", calculator.minus(op1, op2)) elif menunumber == "3": print("\t\t", op1, "*", op2, "=", calculator.multi(op1, op2)) elif menunumber == "4": print("\t\t", op1, "/", op2, "=", calculator.divide(op1, op2)) elif menunumber == "5": print("\t\t", op1, "//", op2, "=", calculator.quotient(op1, op2)) elif menunumber == "6": print("\t\t", op1, "%", op2, "=", calculator.remainder(op1, op2)) elif menunumber == "7": print("\t\t", op1, "**", op2, "=", calculator.square(op1, op2))
import datetime date=datetime.datetime.now() print(date.year) print(date.strftime("%A")) date1=datetime.datetime(2020,1,1) print(date1) print(date1.strftime("%B")) # Day 53 & 54: Challenge #1: import calculator print(calculator.add(8,1)) print(calculator.minus(4,2)) print(calculator.multi(6,6)) print(calculator.divide(8,2)) #2: today=datetime.datetime.now() print(today.year) print(today) print(today.strftime("%B")) print(today.strftime("%A")) #3: yesterday= date.today() - datetime.timedelta(days=1) print(yesterday) tomorrow= date.today() + datetime.timedelta(days=1) print(tomorrow)
def testMulti(self): self.assertEqual(calculator.multi(5, 2), 10) self.assertEqual(calculator.multi(5, -3), -15) self.assertEqual(calculator.multi(-5, 3), 15)
def test_multi(arg, expected_output): assert multi(arg[0],arg[1]) == expected_output
def test_multi_exercise_4d(): assert multi(3,4) == 12
if len(list1) > 2: print("\t점을 두개 입력했어요") elif not list1[0].isdigit(): print("\t점 앞의 숫자를 잘못 입력했어요") elif not list1[1].isdigit(): print("\t점 뒤의 숫자를 잘못 입력했어요") else: return float(operand) print("\t잘못 입력 했어요. 숫자를 입력하세요.") operand = input("\t" + message + " : ") return int(operand) printmenu() menunumber = getMenuNuber() while menunumber != "8": operand1 = getOperand("첫 번째 피연산자를 입력하세요") operand2 = getOperand("두 번째 피연산자를 입력하세요") if menunumber == "1": calculator.plus(operand1, operand2) elif menunumber == "2": calculator.minus(operand1, operand2) elif menunumber == "3": calculator.multi(operand1, operand2) printmenu() menunumber = getMenuNuber()
import calculator from functools import reduce print('25 + 56 = {}'.format(calculator.add(25, 56))) print('86 - 68 = {}'.format(calculator.sub(86, 68))) print('50 * 60 = {}'.format(calculator.multi(50, 60))) print('99 / 25 = {}'.format(calculator.div(99, 25))) print() #********************************************** def canBeDived(x): if x % 3 == 0 and x % 5 == 0: return True print(list(filter(canBeDived, range(0, 100)))) print() #********************************************** def sumODD(x, y): if y % 2 != 0: return x + y return x print(reduce(sumODD, range(1, 100))) print() #**********************************************
def test_multi(self): self.assertEqual(calculator.multi(10, 5), 50) self.assertEqual(calculator.multi(1, 10), 10)
def test_multi(): a = 5 b = 10 assert multi(5, 10) == 50, 'Error when multiplicating'
def test_multi(n, expo): tol = 1e-3 assert abs(multi(n[0], n[1]) - expo) < tol, f'{multi(n[0],n[1])} =! {expo}'
def test_multi(self): self.assertEqual(calculator.multi(10, 5), 50) self.assertEqual(calculator.multi(10, 20), 200) self.assertEqual(calculator.multi(10, 14), 140)
op = input( "What operation would you like, +,-,*,/,memory_store,memory_return,memory_clear,invert,power,exit:" ) num_1 = float(input("Enter your first number: ")) num_2 = input("Enter your second number (leave blank for 'invert' or 'ms'): ") if op == '+': value = calculator.add(float(num_1), float(num_2)) print(num_1, "+", num_2, "=", value) elif op == '-': value = calculator.sub(float(num_1), float(num_2)) print(num_1, "-", num_2, "=", value) elif op == '*': value = calculator.multi(float(num_1), float(num_2)) print(num_1, "*", num_2, "=", value) elif op == '/': value = calculator.divide(float(num_1), float(num_2)) print(num_1, "/", num_2, "=", value) elif op == 'memory_store': calculator.memory_store(value) elif op == 'memory_return': value = calculator.memory_return() print = (value) elif op == 'memory_clear': calculator.memory_clear
def test_multi(self): a = (1, -1) b = (2, -3) self.assertEqual(calculator.multi(a, b), (-1, -5))
def test_multi(self): print('test multi') self.assertEqual(multi(6, 3), 18) self.assertEqual(multi(1, 2), 2) self.assertEqual(multi(10, 5), 50)
def test_multi(self): 100 == calculator.multi(10, 10)