Up and down
Define a function named up_down
that takes a single number as its parameter. Your function return a tuple containing two numbers; the first should be one lower than the parameter, and the second should be one higher.
For example, calling up_down(5)
should return (4, 6)
.
Â
==== SOLUTION ====
You can implement the `up_down` function in Python to return a tuple containing one number lower and one number higher than the input parameter. Here’s how you can do it:
“`python
def up_down(num):
     return (num – 1, num + 1)
# Test the function
print(up_down(5)) # Output: (4, 6)
“`
Explanation:
1. `def up_down(num):`: This line defines a function named `up_down` that takes a single parameter `num`, which is a number.
2. `return (num – 1, num + 1)`: This line returns a tuple containing two elements: `num – 1`, which is one lower than the input number, and `num + 1`, which is one higher than the input number.
So, when you call `up_down(5)`, it returns `(4, 6)` because 4 is one lower than 5, and 6 is one higher than 5.
Â