In what concerns the continuous evaluation solving exercises grade during the semester, you should submit until 23:59 of January 18th
(this exercise will still be available for submission after that deadline, but without counting towards your grade)
[to understand the context of this problem, you should read the class #12 exercise sheet]


In this problem you should submit the functions as described. Inside the functions do not print anything that was not asked!

[IP103] Stay in Touch, Pepe!

Coding skills always come in handy, especially to manage your list of contacts!

The Problem

Write a program that helps you manage your contact list stored in a text file. Your program should include the following functionality:

Constraints

The following constraints are guaranteed in all the test cases that will be given to your program:

The example inputs uses the filename contacts.txt.
To make it easier for you to replicate the examples given below, add the following snippet of code in the beginning of your python file:

    import os
    if os.path.exists("contacts.txt"): os.remove("contacts.txt")
  
This ensures that, if a file named contacts.txt exists in your current directory, it is deleted.
In this way, you guarantee that at the beginning of each execution, there is no file: it will be created and manipulated *independently* between runs.



Example Input 1 Example Output 1
view_contacts("contacts.txt")
Error: File Not Found!
Example Input 2 Example Output 2
delete_contact("contacts.txt", "Miriam Santos")
Error: File Not Found!
Example Input 3 Example Output 3
view_contacts("contacts.txt")
add_contact("contacts.txt", "Miriam Santos", "123456789")
add_contact("contacts.txt", "Pedro Ribeiro", "987654321")
view_contacts("contacts.txt")
Error: File Not Found!
Contact Miriam Santos has been added.
Contact Pedro Ribeiro has been added.
All Contacts:
Miriam Santos, 123456789
Pedro Ribeiro, 987654321
Example Input 4 Example Output 4
view_contacts("contacts.txt")
add_contact("contacts.txt", "Miriam Santos", "123456789")
add_contact("contacts.txt", "Pedro Ribeiro", "987654321")
view_contacts("contacts.txt")
delete_contact("contacts.txt", "Mateus Pereira")
view_contacts("contacts.txt")
Error: File Not Found!
Contact Miriam Santos has been added.
Contact Pedro Ribeiro has been added.
All Contacts:
Miriam Santos, 123456789
Pedro Ribeiro, 987654321
Contact Mateus Pereira not found.
All Contacts:
Miriam Santos, 123456789
Pedro Ribeiro, 987654321
Example Input 5 Example Output 5
view_contacts("contacts.txt")
add_contact("contacts.txt", "Miriam Santos", "123456789")
add_contact("contacts.txt", "Pedro Ribeiro", "987654321")
view_contacts("contacts.txt")
delete_contact("contacts.txt", "Miriam Santos")
view_contacts("contacts.txt")
Error: File Not Found!
Contact Miriam Santos has been added.
Contact Pedro Ribeiro has been added.
All Contacts:
Miriam Santos, 123456789
Pedro Ribeiro, 987654321
Contact Miriam Santos has been deleted.
All Contacts:
Pedro Ribeiro, 987654321
Example Input 6 Example Output 6
add_contact("contacts.txt", "Miriam Santos", "123456789")
view_contacts("contacts.txt")
Contact Miriam Santos has been added.
All Contacts:
Miriam Santos, 123456789
Example Input 7 Example Output 7
add_contact("contacts.txt", "Miriam Santos", "123456789")
Contact Miriam Santos has been added.
Example Input 8 Example Output 8
# Add 1 contact
add_contact("contacts.txt", "Miriam Santos", "123456789")
# Delete contact, file is now empty
delete_contact("contacts.txt", "Miriam Santos")
view_contacts("contacts.txt")
Contact Miriam Santos has been added.
Contact Miriam Santos has been deleted.
No contacts found.
Example Input 9 Example Output 9
add_contact("contacts.txt", "Miriam Santos", "123456789")
add_contact("contacts.txt", "Miriam Santos", "123456789")
add_contact("contacts.txt", "Miriam Santos", "123456789")
add_contact("contacts.txt", "Pedro Ribeiro", "987654321")
view_contacts("contacts.txt")
Contact Miriam Santos has been added.
Contact Miriam Santos has been added.
Contact Miriam Santos has been added.
Contact Pedro Ribeiro has been added.
All Contacts:
Miriam Santos, 123456789
Miriam Santos, 123456789
Miriam Santos, 123456789
Pedro Ribeiro, 987654321
Example Input 10 Example Output 10
add_contact("contacts.txt", "Miriam Santos", "123456789")
add_contact("contacts.txt", "Miriam Santos", "123456789")
add_contact("contacts.txt", "Miriam Santos", "123456789")
add_contact("contacts.txt", "Pedro Ribeiro", "987654321")
view_contacts("contacts.txt")
delete_contact("contacts.txt", "Miriam Santos")
view_contacts("contacts.txt")
Contact Miriam Santos has been added.
Contact Miriam Santos has been added.
Contact Miriam Santos has been added.
Contact Pedro Ribeiro has been added.
All Contacts:
Miriam Santos, 123456789
Miriam Santos, 123456789
Miriam Santos, 123456789
Pedro Ribeiro, 987654321
Contact Miriam Santos has been deleted.
All Contacts:
Pedro Ribeiro, 987654321

Introduction to Programming (CC1024)
DCC/FCUP - University of Porto