
Bradley T. answered 01/23/23
Tutor for Python and High School and Middle School Math
I would suggest using a dictionary for this. If you make the coin values the keys of the dictionary and the coin names the values of the dictionary, you can use the key to get the value.
There are different ways to access the dictionary values, and you can use any, but they need to be treated differently because the sample is telling you to be careful of values that are not valid.
Example:
You can use either method.
- If you decide to go with the square brackets, you must use try except to catch the error and resolve it by printing some message saying not a valid value
- If you decide to use get, rather than printing the results, you can first save it to a variable. Then use an if statement to check if the variable is None. If it is not None, then print some message saying this coin is a penny or whatever it is. If it is None then you can print something about not being valid.
I would suggest using the get method, because intentionally crashing your programming is not for the faint of heart.