Question
I have done 3.1 and 3.2. Just need 4. Without using else, elif, and not function. 4. Implement verify_school_open() Another way to test the above
I have done 3.1 and 3.2. Just need 4. Without using else, elif, and not function.
4. Implement verify_school_open()
Another way to test the above function is with a sanity check/validation test using assert.
This approach is demonstrated in the third code block in the preamble section.
When you pass (day), (is_holiday), (is_snowy), and (is_plowed) to the school_open() function, you get back a result; call it is_open.
There are several things that should be true about these variables:
You should not have a case where (day) represents a weekend (is_weekday is False) and is_open is True
You should not have a case where (is_holiday) is True and is_open is True
You should not have a case where (is_snowy) is True, is_plowed is False, and is_open is True
These will become the asserts for the validation function.
Make a function with the signature
verify_school_open(day, is_holiday, is_snowy, is_plowed, is_open)
This function should assert the three things above. This will allow you to run code of the form:
is_open = school_open(day, is_holiday, is_snowy, is_plowed) verify_school_open(day, is_holiday, is_snowy, is_plowed, is_open)
Here, an incorrect implementation of school_open() has a chance of triggering the asserts in verify_school_open().
(Naturally, the implementation of verify_school_open()) may not be correct, but figuring out why there is a contradiction between the two can still be informative.)
3.1. Implement school_open() (2 points) Write a function named school_open() that takes in variables (that I will call) day, and - day is an int in the range of 1 to 7 (inclusive). 1 represents Sunday, 2 Monday, .., 7 Saturday. - is holiday is a boolean that is True if and only if today is a holiday. - is snowy is a boolean that is True if and only if there is snow. - is plowed is a boolean that is True if and only if any snow has been plowed. If is_snowy is False, then this variable may be either True or False and it doesn't matter. This function should return True if and only is school is open. School can't be open on a weekend (Saturday or Sunday). School can't be open on a holiday. School can't be open if it has snowed and not been plowed. Otherwise, school is open. But forget words, have a big ol' truth table: 3.2. Add asserts to school_open() (2 points) Add an assert to school_open() to ensure that the day parameter is in the 1 to 7 range. And think for a bit about how your solution would have treated a number outside the range. It would probably have run without issues, but something wrong would be happening in some sense without us being aware of it. This should be at the beginning of the function, like in the second code block in the preamble section. (If you want, feel free to ensure that the other values are all of type bool) Note: You are editing the existing function, not making a new oneStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started