0% found this document useful (0 votes)
7 views2 pages

Backend Python Coding For Dbms

This document outlines a Python program for managing a blood bank system. It includes functions to load, save, add, view, and search for donors based on their blood group. The program features a simple command-line interface for user interaction.

Uploaded by

lw26200
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views2 pages

Backend Python Coding For Dbms

This document outlines a Python program for managing a blood bank system. It includes functions to load, save, add, view, and search for donors based on their blood group. The program features a simple command-line interface for user interaction.

Uploaded by

lw26200
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Backend Python Coding

import os
import json

DATA_FILE = "donors.json"

# Load existing donors from file


def load_donors():
if os.path.exists(DATA_FILE):
with open(DATA_FILE, "r") as f:
return json.load(f)
return []

# Save donors to file


def save_donors(donors):
with open(DATA_FILE, "w") as f:
json.dump(donors, f, indent=4)

# Add a new donor


def add_donor(donors):
print("\n--- Add New Donor ---")
name = input("Full Name: ")
age = input("Age: ")
gender = input("Gender (M/F): ")
1 blood_group = input("Blood Group (e.g. A+, O-, etc): ")
contact = input("Contact Number: ")

donor = {
"name": name,
"age": age,
"gender": gender,
"blood_group": blood_group.upper(),
"contact": contact
}
donors.append(donor)
save_donors(donors)
print("✅ Donor added successfully!")

# Display all donors


def view_donors(donors):
print("\n--- Donor List ---")
if not donors:
print("No donors found.")
return
for i, d in enumerate(donors, 1):
print(f"{i}. {d['name']} ({d['blood_group']}) - {d['contact']}")

# Search by blood group


def search_donors(donors):
print("\n--- Search Donors by Blood Group ---")
bg = input("Enter blood group to search: ").upper()
found = [d for d in donors if d["blood_group"] == bg]

if not found:
print("No donors with that blood group.")
else:
print(f"Donors with blood group {bg}:")
for d in found:
print(f"- {d['name']} ({d['contact']})")
# Main Menu
def main():
donors = load_donors()

while True:
print("\n===== Blood Bank Management System =====")
print("1. Add Donor")
print("2. View Donors")
print("3. Search Donors by Blood Group")
print("4. Exit")

choice = input("Enter your choice (1-4): ")

if choice == '1':
add_donor(donors)
elif choice == '2':
view_donors(donors)
elif choice == '3':
search_donors(donors)
elif choice == '4':
print("Exiting... Goodbye!")
break
else:
print("❌ Invalid choice. Please enter 1-4.")

if __name__ == "__main__":
main()

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy