Lab 4, Part 1: Predicates and Functions

Predicates are functions that return a boolean value (True or False). In this part of lab, you'll practice writing predicate functions.

Create a new file called `lab04.py`. Add your name and your partner's name at the top of the file in comments.

Predicate practice: write a predicate for each of the following tasks.

Partner A

`isLegal` returns True if the provided age greater or equal to 21; False otherwise.

Examples:

``````isLegal(19) ==> False
isLegal(25) ==> True
isLegal(21) ==> True``````

``````# isLegal(??) ==> True
# isLegal(??) ==> False
# What happens when ?? is a string?``````

`isJustin` returns True if the provided name is Justin; False otherwise.

Examples:

``````isJustin('Lyn') ==> False
isJustin('Justin') ==> True
isJustin('Bieber') ==> False``````

``````# isJustin(??) ==> True
# isJustin(??) ==> False
# Does case matter with your function? Should it?``````

`notJustinAndLegal` returns True if the provided name is NOT Justin and the age is greater than or equal to 21; False otherwise. Hint: use the two predicates above in this one.

Examples:

``````notJustinAndLegal('Lyn', 35) ==> True
notJustinAndLegal('Justin', 21) ==> False
notJustinAndLegal('Malia', 19) ==> False
``````

``````# notJustinAndLegal(??,??) ==> True
# notJustinAndLegal(??,??) ==> False
# Does order of inputs matter?``````

Partner B

`atLeastDouble` returns True if the second number is at least twice as large as the first number; False otherwise.

Examples:

``````atLeastDouble(5,9) ==> False
atLeastDouble(5,10) ==> True
atLeastDouble(5,15) ==> True``````

``````# atLeastDouble(??,??) ==> True
# atLeastDouble(??,??) ==> False``````

`inOrder` returns True if the three numbers are provided in strictly increasing order; False otherwise.

Examples:

``````inOrder(1, 2, 3)  ==> True
inOrder(1, 2, 2)  ==> False # 2 is not greater than 2
inOrder(2, 4, 6)  ==> True
inOrder(-3, -2, -1)  ==> True``````

Invent your own test cases (more than one test case for True and False):

``````# inOrder(??,??,??) ==> True
# inOrder(??,??,??) ==> True
# inOrder(??,??,??) ==> False
# inOrder(??,??,??) ==> False
# What if all numbers are the same?``````

`upOrDownOrder` returns True if the three numbers are provided in strictly increasing order or strictly decreasing order; False otherwise.

Examples:

``````upOrDownOrder(1, 2, 3)  ==> True
upOrDownOrder(1, 2, 2)  ==> False # 2 is not greater than 2
upOrDownOrder(3, 2, 1)  ==> True
upOrDownOrder(-3, 0, -1)  ==> False``````

Invent your own test cases (more than one test case for True and False):

``````# upOrDownOrder(??,??,??) ==> True
# upOrDownOrder(??,??,??) ==> True
# upOrDownOrder(??,??,??) ==> False
# upOrDownOrder(??,??,??) ==> False``````

Partner A

`isQuint` returns True if the provided residence hall is Beebe, Cazenove, Shafer, Munger or Pomeroy; otherwise returns False.

Examples:

``````isQuint('Tower') ==> False
isQuint('Munger') ==> True
isQuint('Shafer') ==> True
isQuint('Cazenove') ==> True
isQuint('Stone') ==> False``````

Invent your own test cases (more than one test case for True and False):

``````# isQuint(??) ==> True
# isQuint(??) ==> False
# What happens if ?? is a number?
# Does case matter here? Should it?``````