Content ITV PRO
This is Itvedant Content department
Process Ticket Information Using String Operations
Business Scenario
Welcome!
Today is your seventh day as a Junior Data Analyst at the Indian Railways Reservation Department.
The railway reservation system stores passenger ticket details such as passenger names, train names, ticket IDs, coach numbers, and travel dates in text format.
To Complete This Task Successfully, You Will Need Python To:
Manipulate strings using Python methods
Format passenger ticket information
Extract required data from ticket records
Display ticket details in a professional format
Pre-Lab Preparation
Topic: Understanding loops in Python
1) Introduction to Strings
2) String Manipulation Methods
3) String Formatting Techniques
4) String Slicing and Extraction
Click here to download previous lab file: Python Lab 6
git pull origin branchNameTask 1: Manipulate Ticket Information Using String Methods
Git Pull
In the Railway Reservation System, thousands of passenger ticket records are generated every day. These records contain important information such as passenger names, train names, station names, coach numbers, and ticket IDs.
Most of this information is stored in text format (strings).
The railway administration wants the Junior Data Analyst to process and clean ticket information so that all records appear professional, accurate, and consistent across the reservation system.
String manipulation means modifying or processing string data using built-in methods.
1
Write the Program
2
passenger_name = " rahul sharma "
train_name = "rajdhani express"
print("Original Passenger Name:", passenger_name)
print("Uppercase Name:", passenger_name.upper())
print("Formatted Name:", passenger_name.strip().title())
print("Train Name:", train_name.upper())
updated_train = train_name.replace("rajdhani", "Vande Bharat")
print("Updated Train Name:", updated_train)Save the File
ticket_string_operations.ipynb3
Output
Task 2: Format Ticket Details Using String Formatting
1
Write the Program
print("Available Seat Numbers:")
for seat in range(1, 11):
print("Seat Number:", seat)2
Output
Task 3: Extract Ticket Data Using String Slicing
1
Write the Program
total_seats = 5
for booking in range(1, 10):
if booking > total_seats:
print("No Seats Available")
break
if booking == 3:
print("Checking Special Reservation")
continue
pass
print("Seat", booking, "Booked Successfully")2
Output
Great job!
You have successfully completed your lab on Simulate Seat Availability Using Loops.In this lab, you used While Loop, For Loop, Range() Function, Break Statement, Continue Statement, Pass Statement
You are now ready to move to the next stage of Junior Data Analyst.
Checkpoint
Git Push
git push origin branchNameNext-Lab Preparation
Topic: String Handling in Python
1) Introduction to Strings
2) String Manipulation Methods
3) String Formatting Techniques
By Content ITV