Skip to content

Commit

Permalink
Added Basic Contact Manager to Beginner Projects (#471)
Browse files Browse the repository at this point in the history
## Pull Request for PyVerse 💡

### Requesting to submit a pull request to the PyVerse repository.

---

#### Issue Title
**Please enter the title of the issue related to your pull request.**  
Add Basic Contact Manager to Beginner Projects 

- [✅ ] I have provided the issue title.

---

#### Info about the Related Issue
**What's the goal of the project?**  
The aim of the Contact Manager project is to create a simple
command-line application that allows users to efficiently manage their
contacts. The key objectives include:

Contact Management: Enable users to add new contacts with a name and
phone number, view existing contacts, and delete contacts as needed.

User-Friendly Interface: Provide a straightforward command-line
interface that allows users to navigate through options easily.

Data Handling: Implement basic data handling to store and retrieve
contact information within the application's session.

Educational Tool: Serve as an educational resource for those learning
Python, demonstrating concepts like object-oriented programming, user
input handling, and basic data structures.

Overall, the project aims to simplify contact management for users while
offering a hands-on programming experience.

- [✅] I have described the aim of the project.

---

#### Name
**Please mention your name.**  
Adwitya Chakraborty

- [✅] I have provided my name.

---

#### GitHub ID
**Please mention your GitHub ID.**  
adwityac

- [✅] I have provided my GitHub ID.

---

#### Email ID
**Please mention your email ID for further communication.**  
adwityachakraborty@hotmail.com

- [✅] I have provided my email ID.

---

#### Identify Yourself
**Mention in which program you are contributing (e.g., WoB, GSSOC, SSOC,
SWOC).**
Contributor (GSSOC)
- [✅] I have mentioned my participant role.

---

#### Closes
**Enter the issue number that will be closed through this PR.**  
*Closes: #465 *

- [✅] I have provided the issue number.

---

#### Describe the Add-ons or Changes You've Made
**Give a clear description of what you have added or modified.**  
In the Contact Manager project, I've added detailed comments throughout
the code to clarify its functionality and improve readability. These
comments explain the purpose of each class and method, guiding users
through the code structure and flow. Additionally, I included a sample
interaction section at the end of the code, demonstrating how the
application works in practice. This section outlines user inputs and the
corresponding outputs, making it easier for users to understand how to
interact with the program effectively. Overall, these modifications
enhance the educational value of the project by providing context and
examples for users.

- [✅] I have described my changes.

---

#### Type of Change
**Select the type of change:**  
- [ ] Bug fix (non-breaking change which fixes an issue)
- [✅] New feature (non-breaking change which adds functionality)
- [ ] Code style update (formatting, local variables)
- [ ] Breaking change (fix or feature that would cause existing
functionality to not work as expected)
- [ ] This change requires a documentation update

---

#### How Has This Been Tested?
**Describe how your changes have been tested.**  
The changes have been tested by running the contact manager in various
scenarios to ensure all functionalities work as intended. I verified
that users can successfully add contacts, view the list of contacts, and
delete existing contacts. Each operation was tested with valid inputs,
and I also checked how the program responds to invalid inputs, such as
attempting to delete a non-existent contact. The sample interaction
comments were validated against the actual outputs to confirm that they
accurately represent the user experience. This comprehensive testing
process ensured that the code functions correctly and provides a
seamless user experience.

- [✅] I have described my testing process.

---

#### Checklist
**Please confirm the following:**  
- [✅] My code follows the guidelines of this project.
- [✅] I have performed a self-review of my own code.
- [✅] I have commented my code, particularly wherever it was hard to
understand.
- [✅] I have made corresponding changes to the documentation.
- [✅] My changes generate no new warnings.
- [✅] I have added things that prove my fix is effective or that my
feature works.
- [✅] Any dependent changes have been merged and published in downstream
modules.
  • Loading branch information
UTSAVS26 authored Oct 15, 2024
2 parents e0c2437 + d3b5dd6 commit 93c7d19
Showing 1 changed file with 107 additions and 0 deletions.
107 changes: 107 additions & 0 deletions Beginner_Projects/Contact_Manager
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
# Contact Manager
# This is a simple command-line contact manager that allows users to
# add, view, and delete contacts from a list. Each contact consists of
# a name and a phone number.

class Contact:
def __init__(self, name, phone):
self.name = name
self.phone = phone

def __str__(self):
return f"{self.name}: {self.phone}"

class ContactManager:
def __init__(self):
self.contacts = []

def add_contact(self, name, phone):
new_contact = Contact(name, phone)
self.contacts.append(new_contact)
print(f"Contact '{name}' added.")

def view_contacts(self):
if not self.contacts:
print("No contacts available.")
else:
print("Contacts:")
for contact in self.contacts:
print(contact)

def delete_contact(self, name):
for contact in self.contacts:
if contact.name == name:
self.contacts.remove(contact)
print(f"Contact '{name}' deleted.")
return
print(f"Contact '{name}' not found.")

def main():
manager = ContactManager()

while True:
print("\nContact Manager")
print("1. Add Contact")
print("2. View Contacts")
print("3. Delete Contact")
print("4. Exit")

choice = input("Choose an option (1-4): ")

if choice == '1':
# Adding a contact
name = input("Enter contact name: ")
phone = input("Enter contact phone number: ")
manager.add_contact(name, phone)


elif choice == '2':
# Viewing contacts
manager.view_contacts()


elif choice == '3':
# Deleting a contact
name = input("Enter contact name to delete: ")
manager.delete_contact(name)


elif choice == '4':
print("Exiting the Contact Manager. Goodbye!")
break

else:
print("Invalid choice. Please select a valid option.")

# Run the Contact Manager
if __name__ == "__main__":
main()

# Sample Interaction
# Contact Manager
# 1. Add Contact
# 2. View Contacts
# 3. Delete Contact
# 4. Exit
# Choose an option (1-4): 1
# Enter contact name: Alice
# Enter contact phone number: 123-456-7890
# Contact 'Alice' added.

# Contact Manager
# 1. Add Contact
# 2. View Contacts
# 3. Delete Contact
# 4. Exit
# Choose an option (1-4): 2
# Contacts:
# Alice: 123-456-7890

# Contact Manager
# 1. Add Contact
# 2. View Contacts
# 3. Delete Contact
# 4. Exit
# Choose an option (1-4): 3
# Enter contact name to delete: Alice
# Contact 'Alice' deleted.

0 comments on commit 93c7d19

Please sign in to comment.