0% found this document useful (0 votes)
16 views3 pages

Key Access Program for School Roles

The document provides Python programs that demonstrate the use of logical operators: 'and', 'or', and 'not'. Each program checks specific conditions such as number positivity, scholarship eligibility, login credentials, student pass/fail status, and admission eligibility based on score or sports quota. The examples illustrate how to implement these logical operators in various scenarios.

Uploaded by

kritikashar183
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views3 pages

Key Access Program for School Roles

The document provides Python programs that demonstrate the use of logical operators: 'and', 'or', and 'not'. Each program checks specific conditions such as number positivity, scholarship eligibility, login credentials, student pass/fail status, and admission eligibility based on score or sports quota. The examples illustrate how to implement these logical operators in various scenarios.

Uploaded by

kritikashar183
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Python Programs Demonstrating Logical

Operators

Logical Operators - Example Programs


These programs demonstrate the use of logical operators like and , or , and not

1. WAP in Python to check if a number is positive as well


as even or not.
In [4]: # create required variable and assign value
num = 12

# check the two condtitions using 'and' operator then print the result
if num > 0 and num % 2 == 0:
print("The number is positive and even")
else:
print("Condition not satisfied")

The number is positive and even

2. WAP in Python to check if a number is negative or


greater than 100
In [6]: # create required variable and assign value
num = -5

# check if any of the two condtitions is True


# By using 'or' operator then print the result
if num < 0 or num > 100:
print("The number is either negative or greater than 100")
else:
print("The number is between 0 and 100")

The number is either negative or greater than 100

3. WAP in Python to check if student is eligible for


scholarship or not. Criteria: marks should be greater than
80% and attendance should be greater than 90%
In [8]: # create required variables and assign value
marks = 85
attendance = 92

# check if both condtitions are satisfied or not using 'and' operator


# then print the result
if marks > 80 and attendance > 90:
print("Eligible for scholarship")
else:
print("Not eligible for scholarship")

Eligible for scholarship

4. WAP in Python to check if login credentials are


incorrect using not

In [10]: # create required variables and assign value


username = "user"
password = "1234"

# check if both condtitions are inversely satisfied


# using 'not' as well as 'and' operator
# then print the result
if not (username == "admin" and password == "admin123"):
print("Invalid credentials")
else:
print("Correct username and password. Login successful")

Invalid credentials

5. WAP in Python to check pass/fail status of a student's


mark, using not operator

In [12]: # create required variable and assign value


marks = 35

# check if the condtition is inversely satisfied then print result


if not marks >= 40:
print("Student has failed")
else:
print("Student has passed")

Student has failed

6. WAP in Python to check admission eligibility based on


either score or sports quota. Criteria: Score higher than
70 or Quota is present.
In [14]: # create required variables and assign value
score = 65
sports_quota = True

# check if either of the two condtitions is satisfied then print result


if score >= 70 or sports_quota:
print("Eligible for admission")
else:
print("Not eligible for admission")

Eligible for admission

Common questions

Powered by AI

Python's use of 'or' allows eligibility determination when fulfilling at least one condition suffices, such as admittance by score or sports quota. This facilitates versatile decision-making, aligning with diverse criteria requirements .

Logical operators, specifically 'not', play a crucial role in determining outcomes based on conditions such as exam results. By using 'not' before 'marks >= 40', it inverts the condition, leading to a 'fail' status if marks are below 40 .

Logical operators like 'not' help assess if a student's marks do not meet a 'pass' threshold (e.g., not marks >= 40), resulting in a 'fail' status. This provides a clear logical check against a defined threshold, simplifying the pass/fail decision process .

Logical operators like 'and' can check multiple conditions for scholarship eligibility. In Python, both conditions need to be satisfied: marks must be greater than 80%, and attendance over 90%. If both conditions are met using 'and', the student is deemed eligible .

Python employs the 'and' operator to ensure both criteria are fulfilled before executing an action. For example, the eligibility for a scholarship relies on both marks exceeding 80% and attendance surpassing 90%, ensuring both conditions are met for eligibility .

The 'and' operator ensures multiple conditions, such as both positivity and parity of a number, are checked simultaneously. For instance, a number must be both greater than 0 and even to yield positive outcomes, leveraging 'and' to verify dual conditions efficiently .

Logical operators such as 'or' help in decision-making when either scenario could lead to a beneficial or harmful result. By evaluating conditions like negative value or exceeding a threshold with 'or', decisions can anticipate multiple risk or benefit factors simultaneously .

Python simplifies range checks by using the 'or' logical operator to determine if a number is negative or greater than 100. This operator evaluates the truth of either condition, efficiently determining whether a number is outside a specified range .

The 'or' operator is significant in assessing eligibility based on diverse criteria, such as a score above 70 or having a sports quota. By using 'or', Python enables eligibility if either condition is satisfied, reflecting flexibility in meeting admission requirements .

Python uses logical operators like 'not' combined with 'and' to handle login attempts. By using 'not (username == "admin" and password == "admin123")', Python determines invalid credentials if either condition—username or password—is incorrect, thus aiding in identifying incorrect login attempts .

You might also like