def __init__(self, name='bas', age=20, gender='man', weight=80, activitylevel='Vigorously active', goal='Fat loss', length=180, level='Intermediate', body_fat_perc=15): # def __init__(self, name, age, gender, weight, activitylevel, goal, length, level, bodyfatPerc): self.age = int(age) self.gender = gender.lower() self.weight = int(weight) self.activitylevel = activitylevel self.goal = goal self.level = level self.length = int(length) self.body_fat_perc = int(body_fat_perc) # Factors self.goal_factor = self.determine_goal_factor(self.goal) self.activitylevel_factor = self.determine_activitylevel_factor( self.activitylevel) # Calculations self._bmr = Calculator.calculate_bmr(self.gender, self.weight, self.length, self.age) self._tdee = Calculator.calculate_tdee(self.bmr, self.activitylevel_factor, self.goal_factor) self.bmi = Calculator.calculate_bmi(self.weight, self.length) self.ffm = Calculator.calculate_ffm(self.weight, self.body_fat_perc) self.macros = Calculator.calculate_macronutrients( self.weight, self.tdee)
def multiply(a, b): c = Calculator() try: result = c.mul(int(a), int(b)) return str(result) except Exception, e: return str(e.args[0]), 403
def divide(a, b): c = Calculator() try: result = c.div(int(a), int(b)) return str(result) except Exception, e: return str(e.args[0]), 403
def multiply(a, b): c = Calculator() try: result = c.mul(int(a), int(b)) return str(result) except Exception as e: return e.message, 403
def divide(a, b): c = Calculator() try: result = c.div(int(a), int(b)) return str(result) except Exception as e: return e.message, 403
def multiply(a, b): c = Calculator() try: result = c.mul(int(a), int(b)) except ValueTooLowException: return 'Value too low', 403 except ValueTooHighException: return 'Value too high', 403 return str(result)
def test_twoMinusFourteenEqualsNegativeTwelve(self): calc = Calculator() calc.add_digit(2) calc.set_operation(operators["-"]) calc.add_digit(1) calc.add_digit(4) self.assertEqual(calc.get_result(), -12)
def test_twoPlusFourteenEqualsSixteen(self): calc = Calculator() calc.add_digit(2) calc.set_operation(operators["+"]) calc.add_digit(1) calc.add_digit(4) self.assertEqual(calc.get_result(), 16)
def divide(a, b): c = Calculator() try: result = c.div(int(a), int(b)) except ZeroDivisionError: return 'Division by 0', 403 except ValueTooLowException: return 'Value too low', 403 except ValueTooHighException: return 'Value too high', 403 return str(result)
def __init__(self, parent): self.calculator = Calculator() window = PanedWindow(orient=VERTICAL) window.pack(fill=BOTH, expand=10) self.display = Label(window, text="0", justify=RIGHT) window.add(display) bottom = PanedWindow(orient=VERTICAL) zero = Button(bottom, text="0", command=add_digit(0)) one = Button(bottom, text="1", command=add_digit(0)) two = Button(bottom, text="2", command=add_digit(0)) three = Button(bottom, text="3", command=add_digit(0)) four = Button(bottom, text="4", command=add_digit(0)) five = Button(bottom, text="5", command=add_digit(0)) six = Button(bottom, text="6", command=add_digit(0)) seven = Button(bottom, text="7", command=add_digit(0)) eight = Button(bottom, text="8", command=add_digit(0)) nine = Button(bottom, text="9", command=add_digit(0)) bottom.pack(fill=BOTH, expand=1) bottom.add(zero) bottom.add(one) bottom.add(two) bottom.add(three) bottom.add(four) bottom.add(five) bottom.add(six) bottom.add(seven) bottom.add(eight) bottom.add(nine) window.add(bottom)
def multiply(a, b): c = Calculator() result = c.mul(int(a), int(b)) return str(result)
def divide(a, b): c = Calculator() result = c.div(int(a), int(b)) return str(result)
from logic import Calculator operacao = input("Qual operação você deseja fazer: ") num1 = float(input("Indique um primeiro operador: ")) num2 = float(input("Indique o segundo operador: ")) # operacao = "**" # num1 = 10 # num2 = 5 print(Calculator().do_calc(operacao, num1, num2))
def test_ffm_calculation(self): print("Calculator - FFM calculation") ffm = Calculator.calculate_ffm(weight=100, body_fat_perc=20) self.assertEqual(ffm, 80)
def test_bmi_calculation(self): print("Calculator - BMI calculation") bmi = Calculator.calculate_bmi(weight=80,length=180) self.assertEqual(bmi, 25)