In: Computer Science
Write a function that implements the following formula to
calculates the amount of financial assistance for families in
need:
• If the annual family income is between $30,000 and $40,000 and
the family has at least 3 children, the assistance amount will be
$1,000 per child.
• If the annual family income is between $20,000 and $30,000 and
the family has at least 2 children, the assistance amount will be
$1,500 per child.
• If the annual family income is less than $20,000, the assistance
amount will be $1,000 per child.
Write a program that asks for the family income and their number of
children, then prints the amount of assistance that your function
returns. Use -10, as a sentinel value for the input.
The solution is coded in Python 3.9 programmin language.
The code snippet of the required program is attached below:
def financial_assistance(inc,child):
if(inc>30000 and inc <= 40000 and child>=3):
print("The financial assistance amount is: $",str(1000*child))
elif(inc>=20000 and inc <= 30000 and child>=2):
print("The financial assistance amount is: $",str(1500*child))
elif(inc < 20000):
print("The financial assistance amount is: $",str(1000*child))
else:
print("No financial assistance available")
sentinel = 1
while(sentinel != -10):
fam_income = int(input("Enter the annual family income: $"))
children = int(input("Enter the number of children in the family:"))
financial_assistance(fam_income,children)
print("Do you want to calculate financial assistance for another family?")
print("Enter -10 to quit and 1 to continue")
sentinel = int(input())
we have created a function financial_assistance to calculate the financial assistance based on the values of family income and number of children which is provided as arguments from the main program.
The if ..elif..else ladder is coded in according to the conditions provided in the question.
In the main loop the user is requested to provide values of family income and number of children and after calculating the financial assistance the user is asked whether he wants to continue or not.
If the input provided by user is -10 then the program ends running.
The screenshot of the program and the output generated is attached for your reference;
Hope this helps!!!