0% found this document useful (0 votes)
24 views8 pages

Parangat Python Ass

python assignments

Uploaded by

feweve5326
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)
24 views8 pages

Parangat Python Ass

python assignments

Uploaded by

feweve5326
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/ 8

Assignment - 1

Student Name: Gurjeet Singh UID: 24MCS10044

Branch: ME-CSE Section/Group: 24MCS-1/A


Semester: 1st Date of Performance:
02/09/2024
Subject: Advanced Python Programming
Subject Code: 24CSH-622

Question:
Write a Python Program that allows you to input, display, delete and search for a dog in a system.
 To enter a Dog data and add it to the Dog data.
 To display the Dog data
 To delete a Dog's data from system
 To search for a Dog in system.
 Additional features should include such as to check the validation for all parameters.
Create this program using classes, objects and functions.

Answer:
DOG MANAGEMENT SYSTEM
To create the Dog management system as described, we will use object-oriented programming (OOP)
concepts in Python. Here's a brief explanation of the components we'll use:

Classes and Objects:


• Dog Class: Defines the structure and attributes of a Dog, including its ID, name, age, type, gender,
color, and country. It also includes a method to display Dog details.

• Dog Manager Class: Manages a collection of Dog objects, allowing for operations such as adding,
displaying, deleting, and searching for Dogs. It also includes methods for validating Dog data.

Gurjeet Singh 24MCS10044


Methods:
• Initialization Methods ( init ): Used to initialize new objects with specified attributes. The Dog class
initializes Dog attributes, while DogManager initializes an empty list of Dogs.

• Display Method (display): In the Dog class, it prints the Dog’s details. This method is called to show
information about a Dog.

Static Methods:
• validate_Dog: This method is static because it does not need to access or modify instance- specific
data. It performs validation checks on Dog data.

Data Collection and Validation:


• User Input: Data is collected from the user via input prompts.
• Validation Checks: Data is validated against predefined criteria to ensure correctness before being
added to the system.

Control Flow:
• While Loops: Used to repeatedly prompt the user for choices and perform actions based on the user’s
input.
• Conditional Statements (if-else): Determine which actions to take based on user choices or data
validation results.

PYTHON PROGRAM
# Main list to store dog data
dogs = []

# 1. Function to add dog data to the main list


def add_dog():
dog = {}
dog['Dog ID'] = input("Enter Dog ID: ")

Gurjeet Singh 24MCS10044


dog['Name'] = input("Enter Dog Name: ")
dog['Age'] = input("Enter Dog Age: ")
dog['Type'] = input("Enter Dog Type: ")
dog['Gender'] = input("Enter Dog Gender: ")
dog['Color'] = input("Enter Dog Color: ")
dog['Country'] = input("Enter Dog Country: ")
dog['Married'] = input("Is the dog married? (yes/no): ")

dogs.append(dog)
print("Dog added successfully!\n")

# 2. Function to display all dog data


def display_dogs():
if not dogs:
print("No dogs in the system.")
else:
for i, dog in enumerate(dogs, 1):
print(f"Dog {i}:")
for key, value in dog.items():
print(f"{key}: {value}")
print()

# 3. Function to delete a dog from the system using Dog ID


def delete_dog():
dog_id = input("Enter Dog ID to delete: ")
found = False
for dog in dogs:
if dog['Dog ID'] == dog_id:
dogs.remove(dog)
print(f"Dog with ID {dog_id} deleted successfully.\n")
found = True
break
if not found:
print(f"No dog found with ID {dog_id}.\n")

# 4. Function to search for a dog using Dog ID


def search_dog():
dog_id = input("Enter Dog ID to search: ")
found = False
for dog in dogs:
if dog['Dog ID'] == dog_id:
print("Dog found:")
Gurjeet Singh 24MCS10044
for key, value in dog.items():
print(f"{key}: {value}")
print()
found = True
break
if not found:
print(f"No dog found with ID {dog_id}.\n")

# Main loop for interaction


def main():

while True:

print("Dog Management System:")


print("1. Add Dog")
print("2. Display Dogs")
print("3. Delete Dog")
print("4. Search Dog")
print("5. Exit")
choice = input("Choose an option (1-5): ")

if choice == '1':
add_dog()
elif choice == '2':
display_dogs()
elif choice == '3':
delete_dog()
elif choice == '4':
search_dog()
elif choice == '5':
print("Exiting the system.")
break
else:
print("Invalid option. Please choose again.\n")

# Running the main loop


if __name__ == "__main__":
main()

Gurjeet Singh 24MCS10044


PROGRAM EXECUTION RESULT

Gurjeet Singh 24MCS10044


Gurjeet Singh 24MCS10044
Gurjeet Singh 24MCS10044
Gurjeet Singh 24MCS10044

You might also like