New to coding. Need a function that checks whether a number is in a given range (inclusive of high and low)
My attempted solution:
def ran_check(num,low,high):
if num >= low and num <= high:
print(f'{num} is in between the range {low} and {high}')
else:
print(f'{num} is not in between the range {low} and {high}')
The correct solution:
def ran_check(num,low,high):
if num in range(low,high+1):
print(f'{num} is in between the range {low} and {high}')
else:
print(f'{num} is not in between the range {low} and {high}')
No syntax error on either one, but calling the function using the first returns nothing. Why won't the first one work, aren't they the same thing?
UPDATE The issue was with how I was using Jupyter Notebooks, not the code itself. Thanks for the helpful feedback and tips to write this cleaner!