Skip to content

Commit 92fdf42

Browse files
Merge pull request #2357 from andoriyaprashant/branch7
Bus ticket generator script added
2 parents f354076 + 99db5c1 commit 92fdf42

File tree

3 files changed

+97
-0
lines changed

3 files changed

+97
-0
lines changed

Bus ticket generator/README.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Bus Ticket Generator
2+
3+
## Description
4+
The Bus Ticket Generator is a Python script that allows users to generate bus tickets for their journeys. It prompts users to enter details such as passenger name, destination, date of travel, and seat number. The script also provides options to select the type of ticket (one-way or round trip) and the bus service type (seater or sleeper). After entering the details, the script displays a bus ticket with the provided information.
5+
6+
## Features
7+
- Generate bus tickets with passenger details and journey information.
8+
- Select the type of ticket (one-way or round trip) for your journey.
9+
- Choose between two bus service types: seater or sleeper.
10+
- Calculate fare based on the distance and service type.
11+
12+
## Requirements
13+
The script requires Python 3.x to run. No external dependencies are needed as it uses only the Python standard library.
14+
15+
## How to Use
16+
1. Make sure you have Python 3.x installed on your system.
17+
2. Clone this repository to your local machine or download the `bus_ticket_generator_script.py` file.
18+
3. Open a terminal or command prompt and navigate to the directory containing the script.
19+
4. Run the script by executing the following command:
20+
5. Follow the on-screen instructions to enter the passenger details and select the ticket and service type.
21+
6. The script will generate and display the bus ticket with the provided information.
22+
23+
## Installation
24+
To install the dependencies from the requirements file, use the following command in the terminal or command prompt (Bash):
25+
26+
```bash
27+
pip install -r requirements.txt
28+
```
29+
30+
## Have a safe trip!
31+
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import time
2+
3+
def print_delay(text, delay=1):
4+
print(text)
5+
time.sleep(delay)
6+
7+
def calculate_fare(service_type, distance):
8+
seater_rate_per_km = 0.4 # Modify this value for the seater service fare per kilometer
9+
sleeper_rate_per_km = 0.8 # Modify this value for the sleeper service fare per kilometer
10+
11+
if service_type.lower() == "seater":
12+
return seater_rate_per_km * distance
13+
elif service_type.lower() == "sleeper":
14+
return sleeper_rate_per_km * distance
15+
else:
16+
return None
17+
18+
def generate_bus_ticket():
19+
print("Welcome to the Bus Ticket Generator!")
20+
print("Please enter the following details to generate your bus ticket.")
21+
22+
passenger_name = input("Passenger Name: ")
23+
destination = input("Destination: ")
24+
date_of_travel = input("Date of Travel: ")
25+
seat_number = input("Seat Number: ")
26+
27+
print("Select the type of ticket:")
28+
print("1. One-way")
29+
print("2. Round trip")
30+
ticket_type = input("Enter the option number (1 or 2): ")
31+
32+
if ticket_type == "1":
33+
ticket_type = "One-way"
34+
distance = float(input("Enter the distance (in kilometers): "))
35+
service_type = input("Select the bus service type (seater/sleeper): ")
36+
fare = calculate_fare(service_type, distance)
37+
if fare is not None:
38+
print("\n***********************")
39+
print(" BUS TICKET")
40+
print("***********************")
41+
print(f"Passenger Name: {passenger_name}")
42+
print(f"Destination: {destination}")
43+
print(f"Date of Travel: {date_of_travel}")
44+
print(f"Seat Number: {seat_number}")
45+
print(f"Ticket Type: {ticket_type}")
46+
print(f"Bus Service: {service_type}")
47+
print(f"Distance: {distance} km")
48+
print(f"Fare: ${fare:.2f}")
49+
print("***********************")
50+
print(" Have a safe trip!")
51+
print("***********************")
52+
else:
53+
print("Invalid bus service type. Please enter 'seater' or 'sleeper'.")
54+
return
55+
elif ticket_type == "2":
56+
ticket_type = "Round trip"
57+
print("\nRound trip tickets are not currently available. Please check back later.")
58+
else:
59+
print("Invalid option. Please enter '1' or '2' for ticket type.")
60+
return
61+
62+
if __name__ == "__main__":
63+
generate_bus_ticket()

Bus ticket generator/requirements.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
numpy
2+
matplotlib
3+

0 commit comments

Comments
 (0)