Railway Code
Railway Code
# 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: ")
# Log in to Account
def login():
global user_id
try:
user_id = int(input("Enter your ID: "))
password = input("Enter your password: ")
# 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()
# 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