The program I'm writing is to use a given formula to calculate financial assistance for families that loops back and asks the user if they want to do it for another family. Part of the instructs was also to use -1 as a sentinel value for the input. Here is what I have at the moment:
def main():
cont = "y"
while cont.lower() == "y":
try:
income = float(input("Please enter the annual household income:"))
children = int(input("How many children live in the house?"))
amountAssistance = assistanceTotal(income, children)
print("For a household making", income, "per year with", children, " children the amount of assistance would be", amountAssistance)
cont = input("Would you like to run this again? (Y/N)")
except:
print("Something went wrong.")
print("Did you enter a whole number of children?")
cont = input("Would you like to try again? (Y/N)")
def assistanceTotal(money, kids):
if (money >= 30000 and money <= 40000) and kids >= 3:
moneyTotal = 1000 * kids
return moneyTotal
if (money >= 20000 and money <= 30000) and kids >= 2:
moneyTotal = 1500 * kids
return moneyTotal
if money < 20000:
moneyTotal = 2000 * kids
return moneyTotal
main()
I've tried looking up info on using sentinel values with loops like this but I haven't been able to quite grasp if how I'm thinking of using it is correct. For this type of a situation would I need one sentinel value or two, one for income and one for children? I think I would also need to alter my cont statements and change how it reacts if they type in a -1. Any help is appreciated even if it is just directing me to accurate info on how to use sentinels.
Edit to add another sort of follow up question: Do sentinel values have to be numbers or are they most commonly numbers? What is the difference between having a continue portion using yes/no inputs to using sentinel values? For an example: In my text book it shows using a sentinel to stop the loop by asking for either an input of an integer or enter -1 to exit, is this not the same thing as asking continue Y/N?