[Tutor] Python help
Sarah Flores
flores.sarahlu at gmail.com
Sat Sep 4 13:16:16 EDT 2021
Hello!
I have never posted to python.org before.
I am working on an assignment for a class that is meeting virtually and I
am looking for some feedback before I have to turn this in Sunday night
(9/5, midnight pacific time)
Here is the assignment and the code I wrote.
Can you let me know if I'm totally off base? For context, I am a total
noob and this is only my 2nd class in coding. I used mostly the class notes
ppt slides and random youtube videos to figure this out. It is worth like
half of the grade for the class so far.)
*Assignment:*
> * Q1) A non-governmental organization needs a program to calculate the
> amount of financial assistance for needy families. The formula is as
> follows: *(300 points)
> • 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.
> * 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 –1 as a sentinel value for the
> input. *
>
>
Code is attached as a txt file.
> Thank you,
> Sarah
>
Flores.SarahLu at gmail.com
>
-------------- next part --------------
# Q1 Write the following functions and provide a program to test them.
# CONSTANTS
TIER_1 = 1
TIER_2 = 2
TIER_3 = 3
TIER1_MAX = 20000
TIER2_MAX = 30000
TIER3_MAX = 40000
TIER1_BENEFIT = 2000
TIER2_BENEFIT = 1500
TIER3_BENEFIT = 1000
# Variables
childNum = 0
income = 0
aid = 0
# Defining the function
def main():
print("Your household income is $", income)
if income >= TIER3_MAX:
print("Sorry, you are ineligible for financial aid.")
else:
financialAid(income,aid)
return financialAid
# This function determines whether an applicant will qualify for aid & how much.
def financialAid(income,aid):
childNum = int(input("How many children live in your household? "))
if income < TIER1_MAX:
aid = childNum * TIER1_BENEFIT
print("You are eligible for $",TIER1_BENEFIT," per child of assistance")
print("Your financial aid is $", aid)
return aid
elif TIER2_MAX > income >= TIER1_MAX:
if childNum >= TIER_2:
aid = childNum * TIER2_BENEFIT
print("You are eligible for $",TIER2_BENEFIT," per child of assistance")
print("Your financial aid is $", aid)
return aid
else: print ("Sorry. You are ineligible for financial assistance.")
elif TIER3_MAX > income >= TIER2_MAX:
if childNum >= TIER_3:
aid = childNum * TIER3_BENEFIT
print("You are eligible for $",TIER3_BENEFIT," per child of assistance")
print("Your financial aid is $", aid)
return aid
else: aid = 0
print("Sorry. You are ineligible for financial assistance.")
return aid
# This portion includes the while loop and sentinel value (-1)
# This portion also calls the main function
income = int(input("What is the total household income for the first applicant? (enter -1 to end) $"))
while income != -1:
main()
income = int(input("What is the total household income for the next applicant? (enter -1 to end) $"))
More information about the Tutor
mailing list