Git Product home page Git Product logo

goit-pycore-hw-06's Introduction

Address Book System

This is a task for practicing class-based programming. The task is to create an address book system that can store and manage contact information.

Implementation

The system should consist of the following classes:

  • Field: A base class for record fields.
  • Name: A class for storing a contact's name. This field is mandatory.
  • Phone: A class for storing a phone number. It should have validation logic to ensure the number is in the correct format (10 digits).
  • Record: A class for storing information about a contact, including their name and a list of phone numbers.
  • AddressBook: A class for storing and managing records.

Functionality

  • AddressBook:

    • Add records
    • Search records by name
    • Delete records by name
  • Record:

    • Add phone numbers
    • Remove phone numbers
    • Edit phone numbers
    • Search for phone numbers

Recommendations

You can start with the following basic code:

from collections import UserDict

class Field:
    def __init__(self, value):
        self.value = value

    def __str__(self):
        return str(self.value)

class Name(Field):
    # Implement class logic
    pass

class Phone(Field):
    # Implement class logic
    pass

class Record:
    def __init__(self, name):
        self.name = Name(name)
        self.phones = []

    # Implement class logic

    def __str__(self):
        return f"Contact name: {self.name.value}, phones: {'; '.join(p.value for p in self.phones)}"

class AddressBook(UserDict):
    # Implement class logic
    pass

Once implemented, your code should run as follows:

# Create a new address book
book = AddressBook()

# Create a record for John
john_record = Record("John")
john_record.add_phone("1234567890")
john_record.add_phone("5555555555")

# Add John's record to the address book
book.add_record(john_record)

# Create and add a new record for Jane
jane_record = Record("Jane")
jane_record.add_phone("9876543210")
book.add_record(jane_record)

# Print all records in the book
for name, record in book.data.items():
    print(record)

# Find and edit John's phone number
john = book.find("John")
john.edit_phone("1234567890", "1112223333")

print(john)  # Output: Contact name: John, phones: 1112223333; 5555555555

# Search for a specific phone number in John's record
found_phone = john.find_phone("5555555555")
print(f"{john.name}: {found_phone}")  # Output: 5555555555

# Delete Jane's record
book.delete("Jane")

goit-pycore-hw-06's People

Contributors

yevheniidatsenko avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.