In: Computer Science
(Note: anything outside these conditions, there is NO financial assistance)
Implement a function for this computation. Write a program that asks for the household income and number of children for each applicant, printing the amount returned by your function. Use a -1 as a sentinel value for the input.
DefcomputeAssistance (income, children)
Test Cases:
Household income = $35,000 No. of children = 4 (should return $1000/child)
Household income = $25,000 No. of children = 3 (should return $1500/child)
Household income = $18,000 No. of children = 2 (should return $2000/child)
Household income = $40,000 No. of children = 1 (should return “No assistance”)
python keep it simple
Answer: Hope your query is resolved :)
# function to calculate the amount of financial assistance for needy families
def computeAssistance (income, children):
# If the annual household income is between $30,000 and $39,999 and the household has at least three children.
if(income>=30000 and income < 40000 and children >= 3):
return "$1000/child"
# If the annual household income is between $20,000 and $29,999 and the household has at least two children.
elif(income>=20000 and income < 430000 and children >= 2):
return "$1500/child"
# If the annual household income is less than $20,000
elif(income<20000):
return "$2000/child"
# Else NO financial assistance
else:
return "No assistance"
# For user input
n = int(input('Enter any number to continue or -1 to end : '))
while n != -1 : # Using -1 as a sentinal value
income = int(input('Enter Annual household income : $'))
children = int(input('Enter NO. of children : '))
# functional call to compute Financial Assistance
print(computeAssistance(income, children))
n = int(input('Enter any number to continue or -1 to end : '))
Output: