Esempio n. 1
0
def retire():
    """Determine retirement savings and goal"""

    ageString = input("Please enter your age: ")
    while not ageString.isnumeric():
        print("Please enter your age as an integer")
        ageString = input("Enter an integer: ")
    age = int(ageString)

    salaryString = input("Please enter your salary: ")
    while not salaryString.isnumeric():
        print("Please enter your salary as an integer")
        ageString = input("Enter an integer: ")
    salary = float(salaryString)

    savedString = input(
        "Please enter how much you wish to save annually (Ex: 35 = 35%): ")
    while not savedString.isnumeric():
        print("Please enter your annual saving rate as an integer")
        savedString = input("Enter an integer: ")
    saved = float(savedString)

    goalString = input("Please enter your goal: ")
    while not goalString.isnumeric():
        print("Please enter your goal as an integer")
        goalString = input("Enter an integer: ")
    goal = int(goalString)

    result = retirement.findRetirementAge(age, salary, saved, goal)
    if result >= 100:
        print("Sorry, your savings goal will not be met.")
    else:
        print("Your savings goal will be met at: ", result)
def retire():
    args = request.args.to_dict()

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

    age = args["age"]

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

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

    salary = args["salary"]

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

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

    saved = args["saved"]

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

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

    goal = args["goal"]

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

    age = int(age)
    salary = float(salary)
    saved = float(saved)
    goal = int(goal)

    result = retirement.findRetirementAge(age, salary, saved, goal)
    if type(result) is bool or result >= 100:
        return jsonify({"goalMet": False, "age": None})
    else:
        return jsonify({"goalMet": True, "age": result})
Esempio n. 3
0
 def test_saved_below(self):
     self.assertFalse(
         retirement.findRetirementAge(30, 100000.0, -3.0, 50000))
Esempio n. 4
0
 def test_goal_reach2(self):
     self.assertEqual(
         retirement.findRetirementAge(22, 100000.0, 50.0, 200000), 24)
Esempio n. 5
0
 def test_goal_below(self):
     self.assertFalse(retirement.findRetirementAge(30, 100000.0, 35.0, -3))
Esempio n. 6
0
 def test_age_string(self):
     self.assertFalse(
         retirement.findRetirementAge('30', 100000.0, 35.0, 50000))
Esempio n. 7
0
 def test_goal_reach1(self):
     self.assertEqual(
         retirement.findRetirementAge(30, 100000.0, 35.0, 50000), 31)
Esempio n. 8
0
 def test_goal_string(self):
     self.assertFalse(
         retirement.findRetirementAge(30, 100000.0, 35.0, '50000'))
Esempio n. 9
0
 def test_goal_float(self):
     self.assertFalse(
         retirement.findRetirementAge(30, 100000.0, 35.0, 50000.0))
Esempio n. 10
0
 def test_age_out_of_range_above(self):
     self.assertFalse(
         retirement.findRetirementAge(101, 100000.0, 35.0, 50000))
Esempio n. 11
0
 def test_saved_above(self):
     self.assertFalse(
         retirement.findRetirementAge(30, 100000.0, 101.0, 50000))
Esempio n. 12
0
 def test_saved_string(self):
     self.assertFalse(
         retirement.findRetirementAge(30, 100000.0, '35.0', 50000))
Esempio n. 13
0
 def test_saved_int(self):
     self.assertFalse(retirement.findRetirementAge(30, 100000.0, 35, 50000))
Esempio n. 14
0
 def test_salary_below(self):
     self.assertFalse(retirement.findRetirementAge(30, -3.0, 35.0, 50000))
Esempio n. 15
0
 def test_salary_string(self):
     self.assertFalse(
         retirement.findRetirementAge(30, '100000.0', 35.0, 50000))
Esempio n. 16
0
 def test_salary_int(self):
     self.assertFalse(retirement.findRetirementAge(30, 100000, 35.0, 50000))
Esempio n. 17
0
 def test_age_out_of_range(self):
     self.assertEqual(
         retirement.findRetirementAge(95, 100000.0, 1.0, 100000), 100)
Esempio n. 18
0
 def test_age_edge(self):
     self.assertFalse(
         retirement.findRetirementAge(100, 100000.0, 35.0, 100000))