def tip():
    args = request.args.to_dict()

    # subtotal
    if ("subtotal" not in args):
        return "Expected parameter 'subtotal'.", status.HTTP_400_BAD_REQUEST

    subtotal = args["subtotal"]

    if not (subtotal.replace('.', '', 1)).isnumeric():
        return "Parameter 'subtotal' must be a float.", status.HTTP_400_BAD_REQUEST

    subtotal = float(subtotal)

    # subtotal
    if ("partySize" not in args):
        return "Expected parameter 'partySize'.", status.HTTP_400_BAD_REQUEST

    partySize = args["partySize"]

    if not (partySize.replace('.', '', 1)).isnumeric():
        return "Parameter 'partySize' must be an integer.", status.HTTP_400_BAD_REQUEST

    partySize = int(partySize)

    dues = tip_calc.calculateTip(subtotal, partySize)

    return jsonify(dues)
Example #2
0
def tip():
    "Split a tip"
    subtotalString = input("Please enter your sub-total: ")
    while not isDecimalString(subtotalString):
        print("Please enter your subtotal as a decimal number")
        subtotalString = input("Enter a decimal number: ")
    subtotal = float(subtotalString)

    partySizeString = input(
        "Please enter the number of people that are paying: ")
    while not partySizeString.isnumeric():
        print("Please the number of people that are paying as an integer")
        partySizeString = input("Enter an integer: ")
    partySize = int(partySizeString)

    dues = tip_calc.calculateTip(subtotal, partySize)

    for i in range(0, len(dues)):
        print("Guest " + str(i + 1) + " must pay $" + str(round(dues[i], 2)))
 def test_five_way_uneven_split(self):            
       self.assertEqual([3.48, 3.47, 3.47, 3.47, 3.47], tip_calc.calculateTip(15.1, 5))
 def test_require_number_arg2(self):
       for badInput in ["10", True, TestTip()]:
             with self.assertRaises(TypeError):                        
                   tip_calc.calculateTip(1, badInput)
 def test_three_way_uneven_split(self):
       self.assertEqual([0.31, 0.31, 0.30], tip_calc.calculateTip(0.8, 3))
       self.assertEqual([5.83, 5.83, 5.82], tip_calc.calculateTip(15.2, 3))
 def test_two_way_even_split(self):
       self.assertEqual([0.69, 0.69], tip_calc.calculateTip(1.2, 2))
       self.assertEqual([2.99, 2.99], tip_calc.calculateTip(5.2, 2))
 def test_one_way_split(self):
       self.assertEqual([1.15], tip_calc.calculateTip(1, 1))
       self.assertEqual([5.75], tip_calc.calculateTip(5, 1))
 def test_fail_negative_way_split(self):
       with self.assertRaises(ValueError):                        
             tip_calc.calculateTip(1, -1)
 def test_fail_zero_way_split(self):
       with self.assertRaises(ValueError):                        
             tip_calc.calculateTip(1, 0)