forked from werhereitacademy/Python_Modul_Week_2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQuestion3.py
More file actions
103 lines (85 loc) · 3.27 KB
/
Question3.py
File metadata and controls
103 lines (85 loc) · 3.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#Question 3: Customer Management System
#1)Use a dictionary structure to store customer information.
# Assign a unique customer identification (ID) for each customer and associate customer information with this ID.
# You can use a dictionary containing information such as name, surname, e-mail, phone number for each customer.
customers = {} #empty dictionary to hold all customers record
#the key will be the Customer ID
#the value will be another dictionary with customer details
#2)Provide a menu where the user can choose the following actions:
#3)Add New Customer
def add_customer(customers):
cid = input("Enter customer ID: ")
if cid in customers:
print("Customer ID already exists.")
return
name = input("Enter name: ")
surname = input("Enter surname: ")
email = input("Enter email: ")
phone = input("Enter phone number: ")
customers[cid] = {
"name": name,
"surname": surname,
"email": email,
"phone": phone
}
print("Customer added successfully.")
#4)Update Customer Info
def update_customer(customers):
cid = input("Enter customer ID to update: ")
if cid not in customers: # check if the ID exists
print("Customer not found.")
return
print("Current info:", customers[cid])
#get new info from the user
name = input("Enter new name: ")
surname = input("Enter new surname: ")
email = input("Enter new email: ")
phone = input("Enter new phone number: ")
customers[cid] = { #update the customer details
"name": name,
"surname": surname,
"email": email,
"phone": phone
}
print("Customer updated.")
#5)Delete a Customer
def delete_customer(customers):
cid = input("Enter customer ID to delete: ")
if cid in customers: #check if the ID exists
del customers[cid] #del removes an item from a dictionary
print("Customer deleted.")
else:
print("Customer not found.")
#6)List All Customers
def list_customers(customers):
if not customers:
print("No customers in the system.")
return
#Loop through all customers and print their details
for cid, info in customers.items(): #.items() lets us loop through the key and value in the dictionary
print(f"ID: {cid}, Name: {info['name']} {info['surname']}, Email: {info['email']}, Phone: {info['phone']}")
#7)Menu System (Loop until logout)
def main():
customers = {} # main dictionary to store customer data.start with an empty dictionary for customers
while True: #display the menu
print("\nCustomer Management System")
print("1. Add Customer")
print("2. Update Customer")
print("3. Delete Customer")
print("4. List All Customers")
print("5. Exit")
choice = input("Choose an option (1-5): ")
if choice == "1":
add_customer(customers)
elif choice == "2":
update_customer(customers)
elif choice == "3":
delete_customer(customers)
elif choice == "4":
list_customers(customers)
elif choice == "5":
print("Goodbye!")
break
else:
print("Invalid choice. Please try again.")
main()