Question

In: Computer Science

Python code Financial Assistance : A non-governmental organization needs a program to calculate the amount of...

Python code

Financial Assistance : A non-governmental organization needs a program to calculate the amount of financial assistance for needy families.

The formula is as follows:

• If the annual household income is between $30,000 and $40,000 and the household has at least three children, the amount is $1,000 per child.

• If the annual household income is between $20,000 and $30,000 and the household has at least two children, the amount is $1,500 per child.

• If the annual household income is less than $20,000, the amount is $2,000 per child. Write a program that asks for the house-hold income and number of children for each applicant, printing the amount returned by your function.

Input function Specs :

1. def get_income() This function requests an annual household income from the user and continues to ask for the income value unntil the user gets it right. This function should not accept any arguments.

2. def get_number() This function requests a number of children and continues to ask for the number until the user gets it right. This function should not accept any arguments.

3. def compute_assistance(income, number) This function accepts both the annual household income and the number of children as parameters and return the amount of financial assistance.

Input Errors Whenever the user makes an input error, keep at them until they get it right. Do not return from an input function until you have acquired a legal value, even if it takes years.

Solutions

Expert Solution

I have uploaded the Images of the code, Typed code and Output of the Code. I have provided explanation using comments (read them for better understanding).

Images of the Code:

Note: If the below code is missing indentation please refer code Images

Typed Code:

# a function called get_income
# no input parameters
def get_income():
  
# A infinite while loop
# this loop run infinitely until user enter a valid input
while(True):
# reading annual income from user
income=int(input("Enter your annual household income:"))
# if income is a non negative value or valid input
if(income >= 0):
# breaking the loop
break
else:
# printing the Invalid message
print("Invalid Input. Try Again")
# returning the income
return income

# a function called get_number
# no input parameters
def get_number():
# A infinite while loop
# this loop run infinitely until user enter a valid input
while(True):
# reading number of children's from user
number = int(input("Enter number of children's in your family :"))
# if children's is a non negative number or valid input
if(number >= 0):
# breaking the loop
break;
else:
# printing the Invalid message
# Asking input again
print("Invalid Input. Try Again")
# returning the number of children's
return number

# a function called compute_assistance
# with input parameters income and number
def compute_assistance(income, number):
# a variable to store financial assistance amount
financial_assistance=0;
# if income is between $30000 and $40000
# and the household has at least three children(greater than or equal to)
if(30000 <= income < 40000 and number>= 3):
# calculating financial_assistance $1000 per child
financial_assistance = number*1000
# if income is between $20000 and $30000
# and the household has at least two children(greater than or equal to)
elif(20000 <= income < 30000 and number>= 2):
# calculating financial_assistance $1500 per child
financial_assistance = number*1500
# if household income is less than $20000
elif(income<20000):
# calculating financial_assistance $2000 per child
financial_assistance = number*2000
  
# returning the financial_assistance
return financial_assistance;
  
# calling the function get_income
income=get_income()
# calling the function get_number
number=get_number()
# calling the function financial_assistance
financial_assistance=compute_assistance(income,number)
# printing the returned amount
print("The amount of financial assistance is $",financial_assistance)
#code ended here

Output:


If You Have Any Doubts. Please Ask Using Comments.

Have A Great Day!


Related Solutions

A non-governmental organization needs a program to calculate the amount of financial assistance for needy families....
A non-governmental organization needs a program to calculate the amount of financial assistance for needy families. The formula is as follows:5 pts If the annual household income is between $30,000 and $39,999 and the household has at least three children, the amount is $1000 per child. If the annual household income is between $20,000 and $29,999 and the household has at least two children, the amount is $1500 per child. If the annual household income is less than $20,000, the...
Why is it difficult to define the term NGO? (Non Governmental Organization)
Why is it difficult to define the term NGO? (Non Governmental Organization)
This needs to be in Python and each code needs to be separated. Design a class...
This needs to be in Python and each code needs to be separated. Design a class for a fast food restaurant meals that should have 3 attributes; Meal Type (e.g., Burger, Salad, Taco, Pizza); Meal size (e.g., small, medium, large); Meal Drink (e.g., Coke, Dr. Pepper, Fanta); and 2 methods to set and get the attributes. Write a program that ask the user to input the meal type, meal size, and meal drinks. This data should be stored as the...
Python Explain Code #Python program class TreeNode:
Python Explain Code   #Python program class TreeNode:    def __init__(self, key):        self.key = key        self.left = None        self.right = Nonedef findMaxDifference(root, diff=float('-inf')):    if root is None:        return float('inf'), diff    leftVal, diff = findMaxDifference(root.left, diff)    rightVal, diff = findMaxDifference(root.right, diff)    currentDiff = root.key - min(leftVal, rightVal)    diff = max(diff, currentDiff)     return min(min(leftVal, rightVal), root.key), diff root = TreeNode(6)root.left = TreeNode(3)root.right = TreeNode(8)root.right.left = TreeNode(2)root.right.right = TreeNode(4)root.right.left.left = TreeNode(1)root.right.left.right = TreeNode(7)print(findMaxDifference(root)[1])
Write a program in python to calculate the amount each person must pay toward the bill...
Write a program in python to calculate the amount each person must pay toward the bill and toward the tip, for a group of friends who are eating out together. Since you are all friends, it is okay to split the costs evenly. Your program should take as input: The restaurant bill (without tax or tip) as a floating point number The sales tax rate as a floating point number (for example: an 8% tax rate would be 0.08) The...
prepare a 500 to 700 word letter to either a government institution or non governmental organization...
prepare a 500 to 700 word letter to either a government institution or non governmental organization of your choice describing the conditions you encountered on a recent visit to an underdeveloped country. In your letter request financial assistance and / or resources for an intervention in a selected area that you feel will have the most impact on population health
Q: Using Python: Am trying to write a code that can be tested. Any assistance will...
Q: Using Python: Am trying to write a code that can be tested. Any assistance will be appreciated. Would want Help in understanding and solving this example from Data Structure & Algorithms (Computer Science) with the steps of the solution to better understand, thanks. The purpose of this assignment is the application of queues. A prime number is a positive integer other than 1 and is divisible only by 1 and itself. For example, 7 is a prime number because...
In python make a simple code. You are writing a code for a program that converts...
In python make a simple code. You are writing a code for a program that converts Celsius and Fahrenheit degrees together. The program should first ask the user in which unit they are entering the temperature degree (c or C for Celcius, and f or F for Fahrenheit). Then it should ask for the temperature and call the proper function to do the conversion and display the result in another unit. It should display the result with a proper message....
Write a Python program that reads in an amount in cents and prints the dollar amount...
Write a Python program that reads in an amount in cents and prints the dollar amount in that and the remaining value in cents. For example, if the amount reads in is 360 (cents), the program would print 3 dollars and 60 cents. if the amount read in is 75 (cents), the program would print 0 dollars and 75 cents.
please answer this in a simple python code 1. Write a Python program to construct the...
please answer this in a simple python code 1. Write a Python program to construct the following pattern (with alphabets in the reverse order). It will print the following if input is 5 that is, print z one time, y two times … v five times. The maximum value of n is 26. z yy xxx wwww vvvvvv
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT