Skip to content
This repository has been archived by the owner on Nov 3, 2024. It is now read-only.

Ajout d'un gestionnaire de contacts en Python #429

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions .vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"configurations": [
{
"name": "windows-gcc-x86",
"includePath": [
"${workspaceFolder}/**"
],
"compilerPath": "C:/MinGW/bin/gcc.exe",
"cStandard": "${default}",
"cppStandard": "${default}",
"intelliSenseMode": "windows-gcc-x86",
"compilerArgs": [
""
]
}
],
"version": 4
}
24 changes: 24 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "C/C++ Runner: Debug Session",
"type": "cppdbg",
"request": "launch",
"args": [],
"stopAtEntry": false,
"externalConsole": true,
"cwd": ".",
"program": "build/Debug/outDebug",
"MIMode": "gdb",
"miDebuggerPath": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
59 changes: 59 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
{
"C_Cpp_Runner.cCompilerPath": "gcc",
"C_Cpp_Runner.cppCompilerPath": "g++",
"C_Cpp_Runner.debuggerPath": "gdb",
"C_Cpp_Runner.cStandard": "",
"C_Cpp_Runner.cppStandard": "",
"C_Cpp_Runner.msvcBatchPath": "C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Auxiliary/Build/vcvarsall.bat",
"C_Cpp_Runner.useMsvc": false,
"C_Cpp_Runner.warnings": [
"-Wall",
"-Wextra",
"-Wpedantic",
"-Wshadow",
"-Wformat=2",
"-Wcast-align",
"-Wconversion",
"-Wsign-conversion",
"-Wnull-dereference"
],
"C_Cpp_Runner.msvcWarnings": [
"/W4",
"/permissive-",
"/w14242",
"/w14287",
"/w14296",
"/w14311",
"/w14826",
"/w44062",
"/w44242",
"/w14905",
"/w14906",
"/w14263",
"/w44265",
"/w14928"
],
"C_Cpp_Runner.enableWarnings": true,
"C_Cpp_Runner.warningsAsError": false,
"C_Cpp_Runner.compilerArgs": [],
"C_Cpp_Runner.linkerArgs": [],
"C_Cpp_Runner.includePaths": [],
"C_Cpp_Runner.includeSearch": [
"*",
"**/*"
],
"C_Cpp_Runner.excludeSearch": [
"**/build",
"**/build/**",
"**/.*",
"**/.*/**",
"**/.vscode",
"**/.vscode/**"
],
"C_Cpp_Runner.useAddressSanitizer": false,
"C_Cpp_Runner.useUndefinedSanitizer": false,
"C_Cpp_Runner.useLeakSanitizer": false,
"C_Cpp_Runner.showCompilationTime": false,
"C_Cpp_Runner.useLinkTimeOptimization": false,
"C_Cpp_Runner.msvcSecureNoWarnings": false
}
Empty file.
65 changes: 65 additions & 0 deletions Intermediate Level 📁/contacts/contacts.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import json
import os

CONTACTS_FILE = 'contacts.json'

def load_contacts():
"""Charge les contacts depuis le fichier JSON."""
if os.path.exists(CONTACTS_FILE):
with open(CONTACTS_FILE, 'r') as file:
return json.load(file)
return []

def save_contacts(contacts):
"""Sauvegarde les contacts dans le fichier JSON."""
with open(CONTACTS_FILE, 'w') as file:
json.dump(contacts, file, indent=4)

def add_contact(name, phone):
"""Ajoute un contact à la liste."""
contacts = load_contacts()
contacts.append({"name": name, "phone": phone})
save_contacts(contacts)
print(f"Contact ajouté : {name} - {phone}")

def remove_contact(name):
"""Supprime un contact de la liste."""
contacts = load_contacts()
contacts = [c for c in contacts if c['name'] != name]
save_contacts(contacts)
print(f"Contact supprimé : {name}")

def display_contacts():
"""Affiche tous les contacts."""
contacts = load_contacts()
if not contacts:
print("Aucun contact trouvé.")
return
for c in contacts:
print(f"Nom : {c['name']}, Téléphone : {c['phone']}")

def main():
while True:
print("\nGestionnaire de Contacts")
print("1. Ajouter un contact")
print("2. Supprimer un contact")
print("3. Afficher tous les contacts")
print("4. Quitter")

choice = input("Choisissez une option (1-4) : ")
if choice == '1':
name = input("Entrez le nom du contact : ")
phone = input("Entrez le numéro de téléphone : ")
add_contact(name, phone)
elif choice == '2':
name = input("Entrez le nom du contact à supprimer : ")
remove_contact(name)
elif choice == '3':
display_contacts()
elif choice == '4':
break
else:
print("Choix invalide, veuillez réessayer.")

if __name__ == "__main__":
main()