Python Logical Operators with Static and Dynamic Input
Learn Python logical operators like and
, or
, and not
with real-life examples. Each example is shown with both static values and dynamic input using input()
.
Python के लॉजिकल ऑपरेटर and
, or
, और not
को स्टेटिक और यूज़र इनपुट (dynamic input) के साथ सीखें।
Example 1: Student Grade Checker
marks = 85
if marks >= 80 and marks <= 100:
print("Grade A")
elif marks >= 60 and marks < 80:
print("Grade B")
elif marks >= 40 and marks < 60:
print("Grade C")
else:
print("Fail")
Output:
Grade A
Checks student grade using static marks with 'and' condition.
'and' ऑपरेटर से स्टेटिक मार्क्स के आधार पर ग्रेड चेक करता है।
Example 1: Student Grade Checker
marks = int(input("Enter your marks: "))
if marks >= 80 and marks <= 100:
print("Grade A")
elif marks >= 60 and marks < 80:
print("Grade B")
elif marks >= 40 and marks < 60:
print("Grade C")
else:
print("Fail")
Output:
Depends on user input. Try entering 85 → Output: Grade A
Same grade checker but takes marks from user using input().
यूज़र से मार्क्स लेकर ग्रेड चेक करता है।
Example 2: Max Among 3 Numbers
a = 45
b = 78
c = 66
if a > b and a > c:
print("a is the largest")
elif b > c:
print("b is the largest")
else:
print("c is the largest")
Output:
b is the largest
Compares 3 static numbers using 'and' condition.
'and' ऑपरेटर से 3 नंबरों में सबसे बड़ा पता करता है।
Example 2: Max Among 3 Numbers
a = int(input("Enter first number: "))
b = int(input("Enter second number: "))
c = int(input("Enter third number: "))
if a > b and a > c:
print("a is the largest")
elif b > c:
print("b is the largest")
else:
print("c is the largest")
Output:
Try input a=10, b=30, c=20 → Output: b is the largest
Finds largest of 3 numbers from user input.
यूज़र से इनपुट लेकर सबसे बड़ा नंबर चेक करता है।
Example 3: Leap Year Checker
year = 2024
if (year % 4 == 0 and year % 100 != 0) or (year % 400 == 0):
print("Leap Year")
else:
print("Not a Leap Year")
Output:
Leap Year
Checks if a static year is a leap year using logical operators.
एक स्टेटिक वर्ष को लॉजिकल ऑपरेटर से लीप ईयर चेक करता है।
Example 3: Leap Year Checker
year = int(input("Enter a year: "))
if (year % 4 == 0 and year % 100 != 0) or (year % 400 == 0):
print("Leap Year")
else:
print("Not a Leap Year")
Output:
Try input: 2024 → Output: Leap Year
Checks leap year with user input using and/or operators.
यूज़र से इनपुट लेकर लॉजिकल ऑपरेटर से लीप ईयर चेक करता है।