We know how to create global variables to allow different functions in a program to access the same data.
We also know how to use parameters to help functions share data.
The BIG question is:
The algorithm to feed a monkey 20 times and determine the happy count is going to be repackaged into a function called zooKeeperPerformance
This function will determine the happy count after a zoo keeper feeds a monkey 20 times and returns the count.
The main() function now looks like this:
def main():
keeper1 = zooKeeperPerformance()
keeper2 = zooKeeperPerformance()
bestKeeper = evaluateKeepers(keeper1, keeper2)
displayResult(bestKeeper)
The evaluateKeepers() function takes the happy counts of keeper1 and keeper 2 as parameters.
It processes this data as follows:
if the first parameter is greater than the second parameter, the function returns 1
else if the second parameter is greater than the first parameter, the function returns 2
else it returns 0
The displayResult() function takes an integer as a parameter. It processes the integer as follows:
if the integer is 1 the function displays ZooKeeper 1 keeps their job! ZooKeeper 2 is sacked!
else if the integer is 2 the function displays ZooKeeper 2 keeps their job! ZooKeeper 1 is sacked!
else the function displays Both ZooKeepers keep their jobs!
module function return identifier parameter pseudocode return typedefinecalldata type