Question: Question 2 (4 points): Comparing Rainy Seasons Write a function, precipiation(d, a, b) that takes parameters: d: Dictionary mapping a season to an amount of

Question 2 (4 points): Comparing Rainy Seasons

Write a function, precipiation(d, a, b) that takes parameters:

d: Dictionary mapping a season to an amount of precipitation for that season. a: One season b: Another season

Your function should return True if the rainfall in season a was greater than it was in season b, and False otherwise. If the rainfall was equal, return False.

Your function should handle the following errors the following ways:

If either a or b is not a valid season in the dictionary, you should return an error message (as a string) formatted exactly as: "Error: Key is not in Dictionary."

If the values for the rainfall in each season are not valid for comparison, that is, one of them is not a number, return an error message (as a string) formatted exactly as: "Error: Invalid data types in Dictionary?"

You may assume that no test case will produce both types of errors (so you do not need to decide whether or not to return a Key Error or Invalid Type error when you encounter both). However, you should not make any assumptions about the seasons that exist--sometimes there may be a 'potato' season.

precipitation({"Spring": 813, "Summer":337, "Fall": 581, "Winter": 468}, "Spring", "Summer") == True

precipitation({"Spring": 982, "Summer":484, "Fall": 557, "Winter": 313}, "Winter", "Spring") == False

precipitation({"Spring": 887, "Summer":529, "Fall": 616, "Winter": 286}, "Winter", "Potato") == "Error: Key is not in Dictionary."

precipitation({"Spring": 'cats', "Summer": 313, "Fall": 1457, "Winter": 354}, "Summer", "Spring") == 'Error: Invalid data types in Dictionary?'

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!