Python Railway Ticket Booking System with Real-World Logic

🐍 𝗣𝗿𝗮𝗰𝘁𝗶𝗰𝗶𝗻𝗴 𝗣𝘆𝘁𝗵𝗼𝗻 𝘄𝗶𝘁𝗵 𝗮 𝗿𝗲𝗮𝗹-𝘄𝗼𝗿𝗹𝗱 𝗹𝗼𝗴𝗶𝗰-𝗯𝗮𝘀𝗲𝗱 𝗽𝗿𝗼𝗴𝗿𝗮𝗺 I built a small Python program that simulates a railway ticket booking system using basic Python concepts. 𝗧𝗵𝗶𝘀 𝘀𝗰𝗿𝗶𝗽𝘁: Takes user input (name, age, gender) Handles invalid input using try-except Automatically generates a PNR number Assigns berths using the random module Applies conditional logic to decide ticket price and berth preference based on age and gender 💡 𝗖𝗼𝗻𝗰𝗲𝗽𝘁𝘀 𝘂𝘀𝗲𝗱 𝗶𝗻 𝘁𝗵𝗶𝘀 𝗽𝗿𝗼𝗴𝗿𝗮𝗺: User input handling Exception handling (try / except) Conditional statements (if-elif-else) Random number generation Real-world rule-based logic Building small projects like this really helps in understanding how Python works beyond syntax — especially decision-making and flow control. 𝗛𝗲𝗿𝗲’𝘀 𝘁𝗵𝗲 𝗰𝗼𝗱𝗲 👇 ''' import random name=input("enter your name : ") try: age = int(input("Enter your age: ")) except ValueError: print("Invalid age entered. Please enter a number.") exit() Gender=input("enter your gender : ") berths = ["Lower", "Middle", "Upper", "Side Lower", "Side Upper"] assigned_berth = random.choice(berths) pnr = random.randint(1000000000, 9999999999) print(f"PNR Number: {pnr}") if age >= 80: assigned_berth = "Lower" else: assigned_berth = random.choice(berths) if age >=80 and age<100: print(f"your gender is :{Gender}") if Gender=='male': print("price is 200") print(f"your berth is : {assigned_berth}") else: print("price is 150") print(f"your berth is : {assigned_berth}") elif age<80 and age>=60: print(f"your gender is :{Gender}") if Gender=='male': print("price is 500") print(f"your berth is : {assigned_berth}") else: print("price is 450") print(f"your berth is : {assigned_berth}") elif age<60 and age>=30: print(f"your gender is :{Gender}") if Gender=='male': print("price is 2000") print(f"your berth is : {assigned_berth}") else: print("price is 1500") print(f"your berth is : {assigned_berth}") else: print(f"your gender is :{Gender}") if Gender=='male': print("price is 20") print(f"your berth is : {assigned_berth}") else: print("price is 15") print(f"your berth is : {assigned_berth}") ''' 📌 Still learning, experimenting, and improving every day. Would love feedback or suggestions to make this code cleaner or more efficient! #Python #LearningPython #Programming #CodeNewbie #PythonProjects #DeveloperJourney #AIForTechies #TechLearning

  • No alternative text description for this image

To view or add a comment, sign in

Explore content categories