CODING
Railway Management System
from random import randint
# Global variable to store the user ID
user_id = None
# Login Menu
def login_menu():
print("WELCOME TO THE IRCTC PORTAL")
print("1. Create New Account \n"
"2. Log In \n"
"3. Exit")
opt = int(input("Enter your choice: "))
if opt == 1:
create_acc()
elif opt == 2:
login()
else:
e = input("Exit the portal? (Y/N) ")
if e in "Nn":
login_menu()
# Account Creation
def create_acc():
print("Enter the details to create your account:")
global user_id
user_id = randint(1000, 10000)
print(f"Your generated ID is: {user_id}")
password = input("Enter your password: ")
name = input("Enter your name: ")
gender = input("Enter your gender (M/F/O): ")
age = input("Enter your age: ")
dob = input("Enter your date of birth (YYYY-MM-DD):
")
ph = input("Enter your contact number: ")
print("Now you may log in with your newly created
account!")
login()
# Log in to Account
def login():
global user_id
try:
user_id = int(input("Enter your ID: "))
password = input("Enter your password: ")
print(f"Welcome back {user_id}!")
main_menu()
except:
print("Your account was not found!")
print("You can: \n"
"1. Try logging in again \n"
"2. Create a new account")
ch = input("Enter your choice: ")
if ch == "1":
login()
elif ch == "2":
create_acc()
else:
print("Invalid choice!")
x1 = input("Exit the portal? (Y/N) ")
if x1 in "Nn":
login_menu()
# Main Menu
def main_menu():
print("What would you like to do today? \n"
"1. Purchase a Ticket \n"
"2. Check Ticket Status \n"
"3. Request a refund \n"
"4. Account Settings \n"
"5. Logout \n"
"6. Exit")
ch1 = int(input("Enter your choice: "))
if ch1 == 1:
buy_ticket()
elif ch1 == 2:
show_ticket()
elif ch1 == 3:
cancel_ticket()
elif ch1 == 4:
account()
elif ch1 == 5:
login_menu()
else:
exit_prompt()
# Exit Prompt
def exit_prompt():
x2 = input("Would you like to exit? (Y/N) ")
if x2.upper() == "N":
main_menu()
# Back to Main Menu
def back_to_main_menu():
x3 = input("Return to the Main Menu? (Y/N) ")
if x3.upper() == "Y":
print("Returning to Main Menu...")
main_menu()
# Ticket Creation
def buy_ticket():
print("Enter details for your journey: ")
global user_id
i = user_id
pnr = randint(100000, 1000000)
print(f"Your PNR is {pnr}")
train = input("Enter the name of the train: ")
doj = input("Enter the date of your journey (YYYY-
MM-DD): ")
fr = input("Enter the Departing Station: ")
to = input("Enter the Destination Station: ")
print("Ticket purchased successfully!")
back_to_main_menu()
# Ticket Checking
def show_ticket():
try:
pnr = int(input("Enter your PNR: "))
if pnr == randint(100000, 1000000):
print(f"Train: Sample Train \n"
f"Date of Journey: 2024-01-06 \n"
f"From: Station A \n"
f"To: Station B")
back_to_main_menu()
else:
print("Unauthorized! \n"
"Your ID does not match the PNR of
the ticket.")
back_to_main_menu()
except:
ticket_not_found()
# Ask for a refund
def cancel_ticket():
try:
pnr = int(input("Enter the PNR number of the
ticket: "))
if pnr == randint(100000, 1000000):
print("Ticket cancellation successful!")
back_to_main_menu()
else:
print("Unauthorized! \n"
"Your ID does not match the PNR of
the ticket.")
back_to_main_menu()
except:
ticket_not_found()
# If ticket is not found
def ticket_not_found():
print("Ticket not found!")
print("You can: \n"
"1. Try entering your PNR number again \n"
"2. Purchase a ticket \n"
"3. Return to Main Menu \n"
"4. Exit")
ch = int(input("Enter your choice: "))
if ch == 1:
show_ticket()
elif ch == 2:
buy_ticket()
elif ch == 3:
print("Returning to Main Menu...")
main_menu()
else:
exit_prompt()
# Account settings
def account():
print("Do you want to: \n"
"1. Show Account details \n"
"2. Delete Account")
ch = int(input("Enter your choice: "))
if ch == 1:
print(f"ID: {user_id} \n"
f"Name: Sample User \n"
f"Gender: M \n"
f"Age: 25 \n"
f"DOB: 1999-01-01 \n"
f"Phone Number: 1234567890")
back_to_main_menu()
elif ch == 2:
print("Account Successfully Deleted!")
login_menu()
else:
back_to_main_menu()
# Calling the first function, hence starting the
program
if __name__ == "__main__":
login_menu()
OUTPUT
WELCOME TO THE IRCTC PORTAL
1. Create New Account
2. Log In
3. Exit
Enter your choice: 1
Enter the details to create your account:
Your generated ID is: 7755
Enter your password: 123
Enter your name: Raj
Enter your gender (M/F/O): M
Enter your age: 24
Enter your date of birth (YYYY-MM-DD): 12-1-2000
Enter your contact number: 9846000000
Now you may log in with your newly created account!
Enter your ID: 7755
Enter your password: 123
Welcome back 7755!
What would you like to do today?
1. Purchase a Ticket
2. Check Ticket Status
3. Request a refund
4. Account Settings
5. Logout
6. Exit
Enter your choice: 1
Enter details for your journey:
Your PNR is 283304
Enter the name of the train: Express
Enter the date of your journey (YYYY-MM-DD): 10-1-2024
Enter the Departing Station: New Delhi
Enter the Destination Station: Mumbai
Ticket purchased successfully!
Return to the Main Menu? (Y/N) Y
Returning to Main Menu...
What would you like to do today?
1. Purchase a Ticket
2. Check Ticket Status
3. Request a refund
4. Account Settings
5. Logout
6. Exit
Enter your choice: 2
Enter your PNR: 235-7645637
Ticket not found!
You can:
1. Try entering your PNR number again
2. Purchase a ticket
3. Return to Main Menu
4. Exit
Enter your choice: 4
Would you like to exit? (Y/N) y