#exe 7-2 a conversion experience
Create another simple function that converts between units of measurement of any sort. They can be units of practical importance if you like. They might be culinary units such as US tablespoons and Australian tablespoons (which, indeed, are different). They might be computational units such as the gigabyte (when defined as one billion bytes) and the other gigabyte, aka the gibibyte (10243 bytes, which is 1,073,741,824 bytes). Or they might be more fanciful units, such as human years and dog years. Instead of using print() to display the result when your function is finished, return it. This should be a very simple and short program that works much as to_c() does. Work in Jupyter Notebook to develop and test your function. Then, as a final step, place your function in a text file with some test cases at the bottom; those test cases should involve calling your function with different arguments and using print() to display the result.
#converting dog years to human years - using 7 as the most common perception
def to_human(dog):
if dog > 28:
raise ValueError("Sorry, but there was no dog that lived so long... >.<")
return dog * 7
to_human(13)
91
to_human(1)
7
print(to_human(2))
14
to_human(32)
--------------------------------------------------------------------------- ValueError Traceback (most recent call last) /tmp/ipykernel_5203/2462118571.py in <module> ----> 1 to_human(32) /tmp/ipykernel_5203/3021915106.py in to_human(dog) 1 def to_human(dog): 2 if dog > 28: ----> 3 raise ValueError("Sorry, but there was no dog that lived so long... >.<") 4 return dog * 7 ValueError: Sorry, but there was no dog that lived so long... >.<