Create a sequence of numbers using range, then ask the user to enter a number. Inform the user whether or not their number was within the range you specified


This program accepts a number from the user and checks if it falls within a pre-defined range of numbers. The range of numbers is created using the list(range(1, 50)) function, which creates a list of numbers from 1 to 49. Next, the user is prompted to enter a number using the input() function. The input value is stored in the num variable.

The program then checks if the value of num is present in the list of numbers created earlier using the in operator. If the number is present in the list, the program prints "The Number is Within a Range...". If the number is not present in the list, the program checks if the value of num is less than the first element of the list (i.e. 1). If it is, the program prints "Your Number is Low..". If the value of num is greater than the first element of the list, the program prints "Your Number is High..".

Source Code

"""
a = list(range(1,50))
#print(a)
num = int(input("Enter the Number :"))
if num in a:
	print("The Number is a Within a Range...")
else:
	print("The Number is a Not Within a Range...")
"""
a = list(range(1,50))
#print(a)
num = int(input("Enter the Number :"))
if num in a:
	print("The Number is a Within a Range...")
else:
	if num<a[0]:
		print("Your Number is Low..")
	else:
		print("Your Number is High..")
 
 

Output

Enter the Number :7
The Number is a Within a Range...