num = float(input("Enter a number: "))
if 50 <= num <= 100:
print("The number is between 50 and 100.")
else:
print("The number is NOT between 50 and 100.")
#source code --> clcoding.com
Code Explanation:
Taking User Input
num = float(input("Enter a number: "))
The program asks the user to enter a number.
float(input()) is used to allow both integers and decimal values.
Checking if the Number is Between 50 and 100
if 50 <= num <= 100:
This condition checks if the number is greater than or equal to 50 AND less than or equal to 100.
The chained comparison (50 <= num <= 100) is a concise way to check a range.
Printing the Result
print("The number is between 50 and 100.")
else:
print("The number is NOT between 50 and 100.")
If the condition is True, the program prints that the number is in the range.
Otherwise, it prints that the number is NOT in the range.
0 Comments:
Post a Comment