Monday, January 20, 2025

PETROL BUNK BILLING SYSTEM USING PYTHON

 CODE:

from datetime import datetime

print("***Petrol Bunk Billing System***")

petrol_price = 100

diesel_price = 95

print("""

----- Menu-----

1. Petrol

2. Diesel

""")

fuel_choice = int(input("Enter your choice (1 for Petrol, 2 for Diesel): "))


if fuel_choice == 1:

    fuel_type = "Petrol"

    fuel_price = petrol_price

elif fuel_choice == 2:

    fuel_type = "Diesel"

    fuel_price = diesel_price

else:

    print("Invalid choice.")

    exit()

vehicle_number = input("Enter your vehicle number: ")

liters = int(input("Enter the liters of fuel you want: "))

total_cost = liters * fuel_price

current_datetime = datetime.now()

formatted_datetime = current_datetime.strftime("%Y-%m-%d %H:%M:%S")

print(f"""

***Bharath Petroleum***

Date & Time: {formatted_datetime}

Vehicle Number: {vehicle_number}

Fuel: {fuel_type}

Quantity: {liters} liters

Rate: Rs. {fuel_price}/liter

Total Amount: Rs. {total_cost}

***Thank You . Visit Again***

""")

OUTPUT:



BUS TICKET BOOKING SYSTEM

 CODE:

class Bus:

    def __init__(self, bus_route, sp, ep, seats, cost_per_seat):

        self.bus_route = bus_route

        self.sp = sp

        self.ep = ep

        self.seats = seats

        self.available_seats = seats

        self.cost_per_seat = cost_per_seat

        self.booked_seats = [] 

    def book_seat(self, seat_number):

        if 1 <= seat_number <= self.seats:

            if seat_number not in self.booked_seats:

                self.available_seats -= 1

                self.booked_seats.append(seat_number)

                return True

            else:

                print(f"Seat {seat_number} is already booked. Please choose another seat.")

                return False

        else:

            print("Invalid seat number.")

            return False

    def __str__(self):

        return f"{self.bus_route} ({self.sp} to {self.ep}) - {self.available_seats} seats available"

def get_customer_details():

    name = input("Enter your Name: ")

    gender = input("Enter your Gender (M/F): ")

    age = int(input("Enter your Age: "))

    return name, gender, age

def generate_receipt(bus, seat_numbers, customer_name, customer_details, payment_method):

    receipt = f"""

***Welcome to SETC Bus Booking System***


Route: {bus.bus_route}

From: {bus.sp}

To: {bus.ep}

Seats Booked: {', '.join(map(str, seat_numbers))}

Customer Name: {customer_name}

Gender: {customer_details[1]}

Age: {customer_details[2]}

Cost: Rs.{bus.cost_per_seat * len(seat_numbers)}

Payment Method: {payment_method}


***Thank You for Choosing Us!***

"""

    with open(f"receipt_{bus.bus_route}_{customer_name}.txt", "w") as file:

        file.write(receipt)

    print("Receipt downloaded.")

def main():

    buses = [

        Bus("SETC1", "Coimbatore", "Udumalpet", 60, 150),

        Bus("SETC2", "Pollachi", "Palani", 55, 120),

        Bus("SETC3", "Palani", "Madurai", 50, 180)

    ]

    while True:

        print("\n-----Menu-----\n1. View Buses\n2. Book Seats\n3. Exit")

        choice = input("Enter choice: ")

        if choice == '1':

            print("\nAvailable Routes:")

            for i, bus in enumerate(buses):

                print(f"{i + 1}. {bus}")

        elif choice == '2':

            print("\n***Welcome to SETC Bus Booking System***")

            bus_index = int(input("Choose bus number: ")) - 1

            if 0 <= bus_index < len(buses):

                seats_requested = int(input("How many seats do you want to book? : "))

                if seats_requested > 0:

                    booked_seats = []

                    for _ in range(seats_requested):

                        while True:

                            try:

                                seat_number = int(input(f"Enter desired seat number (1-{buses[bus_index].seats}): "))

                                if buses[bus_index].book_seat(seat_number):

                                    booked_seats.append(seat_number)

                                    break

                            except ValueError:

                                print("Invalid seat number. Please enter a number.")

                    if len(booked_seats) == seats_requested:

                        customer_details = get_customer_details()

                        payment_method = input("Enter payment method (Card/Cash): ").upper()

                        generate_receipt(buses[bus_index], booked_seats, customer_details[0], customer_details, payment_method)

                    else:

                        print("Seat booking failed.") 

                else:

                    print("Invalid number of seats.")

            else:

                print("Invalid bus number.")

        elif choice == '3':

            print("Thank you for using us!.")

            break

        else:

            print("Invalid choice. Please try again.")

if __name__ == "__main__":

    main()

OUTPUT:








ATM USING PYTHON

 CODE:

from datetime import datetime

import random

class ATM:

    def __init__(self, initial_balance):

        self.account_number = "ACC" + str(random.randint(1000000000, 9999999999))  # Generate 11-digit account number

        self.balance = initial_balance

        self.transaction_history = []

    def display_menu(self):

        print("\nWelcome to the ATM")

        print("1. Check Balance")

        print("2. Withdraw")

        print("3. Mini Statement")

        print("4. Exit")

    def check_balance(self):

        print(f"Your current balance is: {self.balance:.2f}") 

    def withdraw(self, amount):

        if amount > 0 and amount <= self.balance:

            old_balance = self.balance

            self.balance -= amount

            current_time = datetime.now().strftime("%Y-%m-%d %H:%M:%S")

            self.transaction_history.append(f"[{current_time}] Withdrawal: -{amount:.2f} | Old Balance: {old_balance:.2f} | New Balance: {self.balance:.2f}") 

            return True  # Indicate successful withdrawal

        else:

            print("Insufficient funds.")

            return False

    def mini_statement(self):

        print("\n=== Mini Statement ===")

        print(f"Account Number: {self.account_number}")

        if not self.transaction_history:

            print("No recent transactions.")

        else:

            for transaction in self.transaction_history[-5:]: 

                print(transaction)

        print("======================")

def generate_withdrawal_receipt(amount, old_balance):

    current_time = datetime.now().strftime("%Y-%m-%d %H:%M:%S")

    print("\n--- Withdrawal Receipt ---")

    print(f"Date/Time: {current_time}")

    print(f"Withdrawal Amount: {amount:.2f}")

    print(f"Old Balance: {old_balance:.2f}")

    print(f"Current Balance: {old_balance - amount:.2f}")  # Calculate and display current balance

    print("-------------------------")

def validate_pin():

    """Validates the ATM PIN."""

    correct_pin = 3215  # Replace with your desired PIN

    attempts = 3

    while attempts > 0:

        entered_pin = int(input("Enter your ATM PIN: "))

        if entered_pin == correct_pin:

            print("PIN verified successfully.")

            return True

        else:

            attempts -= 1

            print(f"Incorrect PIN. {attempts} attempts remaining.")

    print("PIN verification failed. Exiting.")

    return False

if __name__ == "__main__":

    initial_balance = 50000  # Initial balance

    if validate_pin():

        atm = ATM(initial_balance) 

        while True:

            atm.display_menu()

            choice = int(input("Enter your choice: "))

            if choice == 1:

                atm.check_balance()

            elif choice == 2:

                withdrawal_amount = int(input("Enter the amount to withdraw: "))

                if atm.withdraw(withdrawal_amount):

                    generate_withdrawal_receipt(withdrawal_amount, atm.balance + withdrawal_amount) 

            elif choice == 3:

                atm.mini_statement()

            elif choice == 4:

                print("Thank you for using the ATM.")

                break

            else:

                print("Invalid choice. Please try again.")

OUTPUT:



















PETROL BUNK BILLING SYSTEM USING PYTHON

 CODE:


from datetime import datetime


def generate_bill():

    print("\n***WELCOME TO BHARAT PETROLEUM***\n")

    

    while True:

        print("\n***BILL***")

        customer_name = input("Enter customer name: ").strip()

        vehicle_no=input("Enter vehicle number:").strip()

        

        bill_no = f"hi{datetime.now().strftime('%d%m%y%H%M%S')}"

        date_time = datetime.now().strftime("%d-%m-%y %H:%M:%S")

        fuel_type = input("Enter fuel type (Petrol/Diesel): ").strip().capitalize()

        price_per_liter = float(input(f"Enter price per liter for {fuel_type}: "))

        quantity = float(input("Enter quantity in liters: "))

        

        total_cost = price_per_liter * quantity

        print("\n***Generating Bill***\n")

        print("*****BHARAT PETRILEUM *****")

        print(f"Bill No   : {bill_no}")

        print(f"Date/Time : {date_time}")

        print(f"Customer  : {customer_name}")

        print(f"Fuel Type : {fuel_type}")

        print(f"Quantity  : {quantity:.2f} liters")

        print(f"Price/Ltr : ₹{price_per_liter:.2f}")

        print(f"Total Cost: ₹{total_cost:.2f}")

        print("-----------------------")

        print("Thank you! Visit Again!")

        print("-----------------------\n")

        

        proceed = input("Do you want to process another transaction? (yes/no): ").strip().lower()

        if proceed != "yes":

            print("\n***THANKYOU.*** Goodbye!")

            break

if __name__ == "__main__":

    generate_bill()

OUTPUT:



BUS TICKET BOOKING SYSTEM USING PYTHON

 CODE:

import datetime

bus_details = {

    "bus_no": "Priya Travels",

    "source": None,

    "destination": None,

    "total_seats": 60,

    "booked_seats": [],

    "ticket_price": 500

}

def set_bus_route():

    

    print("\n** Set Bus Route **")

    bus_details['source'] = input("Enter Source: ")

    bus_details['destination'] = input("Enter Destination: ")

    print(f"\nRoute Set: {bus_details['source']} -> {bus_details['destination']}")

def display_bus_details():

    

    print("\n*** Bus Details ***")

    print(f"Bus Number: {bus_details['bus_no']}")

    print(f"Route: {bus_details['source']} -> {bus_details['destination']}")

    print(f"Total Seats: {bus_details['total_seats']}")

    print(f"Available Seats: {bus_details['total_seats'] - len(bus_details['booked_seats'])}")

def generate_bill_receipt(name, gender, age, num_seats, seat_numbers, total_amount):

    

    print("\n--- Payment Receipt ---")

    print(f"Passenger Name: {name}")

    print(f"Gender: {gender}")

    print(f"Age: {age}")

    print(f"Bus Number: {bus_details['bus_no']}")

    print(f"Route: {bus_details['source']} -> {bus_details['destination']}")

    print(f"Number of Seats Booked: {num_seats}")

    print(f"Seat Numbers: {', '.join(map(str, seat_numbers))}")

    print(f"Total Amount Paid: ₹{total_amount}")

    print(f"Booking Date and Time: {datetime.datetime.now().strftime('%d-%m-%y %H:%M:%S')}")

    print("\nBooking Successful!")

    print("-----------------------")

def book_ticket():

    

    if not bus_details['source'] or not bus_details['destination']:

        print("\nRoute not set! Please set the source and destination first.")

        return


    display_bus_details()

    if len(bus_details['booked_seats']) >= bus_details['total_seats']:

        print("\nSorry, no seats are available!")

        return


    name = input("\nEnter Passenger Name: ")

    gender = input("Enter Gender (Male/Female/Other): ")

    age = input("Enter Age: ")


    try:

        age = int(age)

        if age <= 0:

            print("Invalid age. Please enter a valid positive number.")

            return

    except ValueError:

        print("Invalid input for age. Please enter a number.")

        return


    num_seats = int(input("Enter Number of Seats to Book: "))


    if num_seats > (bus_details['total_seats'] - len(bus_details['booked_seats'])):

        print("\nNot enough seats available!")

        return


    seat_numbers = []

    for _ in range(num_seats):

        for seat in range(1, bus_details['total_seats'] + 1):

            if seat not in bus_details['booked_seats']:

                bus_details['booked_seats'].append(seat)

                seat_numbers.append(seat)

                break


    total_amount = num_seats * bus_details['ticket_price']



    generate_bill_receipt(name, gender, age, num_seats, seat_numbers, total_amount)


def main_menu():

    

    while True:

        print("\n**** Bus Ticket Booking System ****")

        print("1. Set Bus Route")

        print("2. View Bus Details")

        print("3. Book a Ticket")

        print("4. Exit")

        choice = input("\nEnter your choice: ")


        if choice == "1":

            set_bus_route()

        elif choice == "2":

            display_bus_details()

        elif choice == "3":

            book_ticket()

        elif choice == "4":

            print("\nThank you for using the Bus Ticket Booking System!")

            break

        else:

            print("\nInvalid choice! Please try again.")


if __name__ == "__main__":

    main_menu()


OUTPUT:

 







ATM USING PYTHON

 CODE:

from datetime import datetime

class ATM:

    def __init__(self):

        self.pin = None

        self.balance = 5000

    def set_pin(self):

        while True:

            pin = input("Set a 4-digit ATM PIN: ")

            if len(pin) == 4 and pin.isdigit():

                self.pin = pin

                print("PIN set successfully!")

                break

            else:

                print("Invalid PIN. Please enter a 4-digit number.")

    def verify_pin(self):

        attempts = 3

        while attempts > 0:

            entered_pin = input("Enter your 4-digit ATM PIN: ")

            if entered_pin == self.pin:

                print("PIN verified successfully.")

                return True

            else:

                attempts -= 1

                print(f"Incorrect PIN. You have {attempts} attempts left.")

        print("Too many incorrect attempts. Exiting.")

        return False

    def show_balance(self):

        print("Your current balance is:", self.balance)

    def withdraw(self):

        amount = int(input("Enter the amount to withdraw: "))

        if 0 < amount <= self.balance:

            self.balance -= amount

            print("Amount withdrawn successfully.")

            self.generate_bill(amount)

        elif amount > self.balance:

            print("Insufficient funds.")

        else:

            print("Invalid withdrawal amount.")

    def generate_bill(self, amount):

        current_time = datetime.now().strftime("%d-%m-%y %H:%M:%S")

        print("\n***Transaction Receipt***")

        print(f"Date and Time: {current_time}")

        print(f"Withdrawn Amount: {amount}")

        print(f"Remaining Balance: {self.balance}")

        print("Thank you! Visit again.")

        print("********************")

def main():

    atm = ATM()

    print("\nWelcome to the IOB ATM!")

    atm.set_pin()  

    while True:

        print("\n***Welcome to the IOB ATM***")

        print("1. Check Balance")

        print("2. Withdraw")

        print("3. Exit")

        choice = input("Enter your choice: ")

        if choice in ['1', '2']:

            if atm.verify_pin(): 

                if choice == '1':

                    atm.show_balance()

                elif choice == '2':

                    atm.withdraw()

        elif choice == '3':

            print("Thank you for using the ATM.")

            break

        else:

            print("Invalid choice")

if __name__ == "__main__":

    main()

OUTPUT:
 
 







PETROL BUNK BILLING SYSTEM USING PYTHON

  CODE: from datetime import datetime print("***Petrol Bunk Billing System***") petrol_price = 100 diesel_price = 95 print("...