A function to add two given numbers.
(num1: typing.Union[int, float], num2: typing.Union[int, float])
| 3 | |
| 4 | |
| 5 | def addition(num1: typing.Union[int, float], num2: typing.Union[int, float]) -> str: |
| 6 | """A function to add two given numbers.""" |
| 7 | |
| 8 | # Checking if the given parameters are numerical or not. |
| 9 | if not isinstance(num1, (int, float)): |
| 10 | return "Please input numerical values only for num1." |
| 11 | if not isinstance(num2, (int, float)): |
| 12 | return "Please input numerical values only for num2." |
| 13 | |
| 14 | # Adding the given parameters. |
| 15 | sum_result = num1 + num2 |
| 16 | |
| 17 | # returning the result. |
| 18 | return f"The sum of {num1} and {num2} is: {sum_result}" |
| 19 | |
| 20 | |
| 21 | print(addition(5, 10)) # This will use the provided parameters |