let's design a program using Boolean expressions and if statements the public transit system wants to build an app that determines a passenger's bus Fair the standard bus fair is 425 however they offer discounts for certain age groups kids under five ride for free and seniors those who are 60 and over get a dollar off their Fair we want to break down the problem so we can focus on getting one piece working at a time let's start with the kids case first we want to come up with a Boolean expression that's going to be the condition
for our if statement this Boolean expression should ask the question does this passenger qualify as a kid for the purposes of the bus Fair we said a kid must be under five that means we need some data about the passenger in order to answer this question we need to know their age so we'll add an input function call that asks the user to enter their age then our Boolean expression would be age less than five let's test that expression real quick o okay we got to type error the error message says the less than operator
is not supported between instances of string an integer H age less than five I guess it's saying age is a string ah okay cuz I didn't cast the result of the input function to an integer so age is storing the string three and not the integer three okay let's test that again that's evaluating to True which is correct now let's try the case where they're over five and now let's try the case where they're exactly five awesome okay double checking my requirements it's correct that passengers who are five should not qualify for the kids fair
so this is working as intended we've got a working condition let's put it in an if statement and we make sure to end this with a colon now what do we want to happen if the passenger is a kid well we want their bus fair to be free to do that inside the if statement we can set the variable bus fair to zero inside means indented one tab over let's check our work there and test both cases and while we're at it I'm going to inline this condition into the if statement it's functionally equivalent but
it looks a bit cleaner especially with a condition so short now let's do the same for the senior's case the condition for a senior is 60 and over so we'll want our Boolean expression to be age greater than 60 however this is inclusive so if you are 60 you are a senior so this should actually be greater than or equal to 60 we put that in if statement and then if the person is a senior we want to take a dollar off their fair so the instruction we want indented inside the if statement should subtract
a dollar from the existing bus Fair let's test that with both cases where the user is a senior and where the user isn't and let's also check that our kidss case didn't break now why did I write this assignment statement as bus Fair minus one instead of just setting it directly to 325 this way is a bit more future proof If the transit authority later needs to raise the bus Fair by0 50 cents I can just change this first assignment statement to $475 and the dollar offc your discount will still work if I had instead
set it to 325 I would have to remember to come back here and update this to 375 as well one less requirement the transit authority wants the app to tell the passenger which Fair they qualified for in addition to the price one way to do that could be to just add a print function call inside each of these if statements I don't love that user experience I would rather the existing print statement just print out the fair type so it might say the senior bus fair is 325 that means we need to remember the fair
type so it's still available by the time we get to this print statement at the end sounds like we need a new variable inside the senior if statement will set the fair type to the string senior and inside the kids if statement will set the fair type to the string kids then we can concatenate the fair type into our print statement okay now let's go in and check all of the possible cases we start with the senior case looks like that works then the kids case looks like that works and we also want to check
the standard case where neither if condition evaluates to True whoops that gives us a name error the variable fair type is not defined which makes sense because the assignment statements to fair type only exist indented inside the if statement that means if both conditions evaluate to false neither of these assignment statements run so we need to initialize the variable fair type so it exists in the standard case nice it works I'm going to get started on the transit authorities next feature request deducting bus faires from the users's balance