Python Exercise: Check whether a number is in a given range
Python Functions: Exercise-6 with Solution
Write a Python function to check whether a number is in a given range.
def test_range(n): if n in range(3,9): print( " %s is in the range"%str(n)) else : print("The number is outside the given range.") test_range(5)
5 is in the range
Visualize Python code execution:
The following tool visualize what the computer is doing step-by-step as it executes the said program:
Python Code Editor:
Have another way to solve this solution? Contribute your code (and comments) through Disqus.
Previous: Write a Python function to calculate the factorial of a number (a non-negative integer). The function accepts the number as an argument.
Next: Write a Python function that accepts a string and calculate the number of upper case letters and lower case letters.
What is the difficulty level of this exercise?