Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Visual Basic 4 Ole Database And Controls Superbible

Authors: Michael Hatmaker, C. Woody Butler, Ibrahim Malluf, Bill Potter

1st Edition

1571690077, 978-1571690074

More Books

Students also viewed these Databases questions

Question

Describe the appropriate use of supplementary parts of a letter.

Answered: 1 week ago