Content ITV PRO
This is Itvedant Content department
Applying Conditional Logics for Operators
Business Scenario
Welcome!
Today is your fifth day as a Junior Data Analyst at the Indian Railways Reservation Department. Previously you learned how to use conditional statements
Today, your manager wants you to apply multiple conditions together before confirming reservations and allocating seats to verify eligibility and automate confirmation
Pre-Lab Preparation
To complete this task successfully, using Python you must :
Verify passenger eligibility
Apply reservation rules
Check multiple conditions together
Automate ticket confirmation decisions
git pull origin branchNameGit Pull
Topic: Apply Conditional Logics
1) Use Logical Operators
1
Task 1: Using AND Operator
Create variables for passenger details
passenger_age = 25
ticket_confirmed = TrueApply AND logical operator
2
if passenger_age >= 18 and ticket_confirmed:
print("Passenger Eligible for Travel")Task 2: Using OR Operator
1
Create seat availability variables
Output
3
Apply OR logical operator
2
confirmed_seat = False
rac_seat = Trueif confirmed_seat or rac_seat:
print("Reservation Available")Task 3: Using NOT Operator
1
Create cancellation status variable
ticket_cancelled = FalseOutput
3
2
Apply NOT logical operator
if not ticket_cancelled:
print("Ticket is Active")Task 4: Apply Reservation Rules for Senior Citizens
1
Create passenger details
passenger_age = 65
payment_completed = TrueOutput
3
Apply reservation condition
2
if passenger_age >= 60 and payment_completed:
print("Senior Citizen Reservation Approved")Task 6: Build Ticket Confirmation System
Output
3
Create reservation details
1
available_seats = 5
payment_status = TrueApply confirmation logic
2
if available_seats > 0 and payment_status:
print("Ticket Confirmed Successfully")
else:
print("Reservation Failed")Output
3
Create Passenger Details
1
Task 6: Check Passenger Eligibility for Tatkal Booking
valid_id_proof = True
booking_time_valid = TrueApply Tatkal booking conditions
2
if valid_id_proof and booking_time_valid:
print("Tatkal Booking Allowed")
else:
print("Tatkal Booking Denied")Output
3
Create Reservation Details
1
Task 7: Build Final Reservation Rule Validation Module
passenger_name = "Rahul Sharma"
passenger_age = 30
available_seats = 2
payment_completed = True
ticket_cancelled = FalseApply final reservation validation
2
if (
passenger_age >= 18 and
available_seats > 0 and
payment_completed and
not ticket_cancelled
):
print("===================================")
print(" Indian Railways Reservation ")
print("===================================")
print("Passenger Name :", passenger_name)
print("Reservation Status : Confirmed")
else:
print("Reservation Failed")
Output
3
Save File as : reservation.ipynb
4
Great job!
You have successfully applied AND, OR, and NOT operators to verify passenger eligibility and seat availability and Enhanced the Reservation System by automating reservation rule checking
Checkpoint
Git Push
git push origin branchNameNext-Lab Preparation
Topic: Understanding loops in Python
1) Loops in Python (While and For Loop)
2) Range() function
3) Break ,Continue, Pass
By Content ITV