Skip to content

Instantly share code, notes, and snippets.

@thomasms
Last active May 4, 2024 11:51
Show Gist options
  • Save thomasms/5f9550e0b1ea5f9db068cf2f44de8b38 to your computer and use it in GitHub Desktop.
Save thomasms/5f9550e0b1ea5f9db068cf2f44de8b38 to your computer and use it in GitHub Desktop.
Student Loan Abroad payment plan 1
import argparse
countries = {
'belgium': {'currency': 'EUR', 'rate': 0.869943, 'threshold': 24990, 'default': 390},
'france': {'currency': 'EUR', 'rate': 0.869943, 'threshold': 19995, 'default': 312},
}
def plan1(annual_salary_in_currency: float, country: str) -> float:
data = countries.get(country)
salary_in_gbp = annual_salary_in_currency*data.get('rate')
threshold_in_gbp = data.get('threshold')
monthly_payment = max(0, (salary_in_gbp - threshold_in_gbp)*0.09/12)
return monthly_payment/data.get('rate')
def inverse_plan1(monthly_payment_in_currency: float, country: str) -> float:
data = countries.get(country)
annual_payment_in_gbp = monthly_payment_in_currency*12*data.get('rate')
threshold_in_gbp = data.get('threshold')
salary_in_gbp = threshold_in_gbp + (annual_payment_in_gbp/0.09)
return salary_in_gbp/data.get('rate')
def main():
parser = argparse.ArgumentParser()
parser.add_argument('salary')
parser.add_argument('-c', '--country', default='france')
args = parser.parse_args()
s = float(args.salary)
c = args.country
d = countries.get(c)
dp = d.get('default')/d.get('rate')
print(f"{c}: {plan1(s, c)} EUR / month")
print(f"Default payment is equivalent to salary of {inverse_plan1(dp, c)} EUR / year")
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment