-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpython-user-crud.py
More file actions
104 lines (67 loc) · 2.35 KB
/
python-user-crud.py
File metadata and controls
104 lines (67 loc) · 2.35 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
104
user_information = {
"id": 12345,
"name": "juan",
"last name": "gomez",
"age": 23,
"gender": "male",
"email": "juan.gomez@email.com",
"phone": "+54 9 11 1234-5678"
}
def create_information(a):
while True:
key = input("Enter a key to register or type 'exit' to exit: ").lower()
if key == "exit":
break
if key.isdigit():
key = int(key)
if key in a:
print(f"'{key}' is already registered!")
continue
value = input("Enter a value to register: ").lower()
if value.isdigit():
value = int(value)
if not key in a:
a.update({key: value})
print(f"'{key}' and its value '{value}' were successfully registered!")
break
def read_information(a):
if not a:
print("There is no information to display.")
else:
current_information = "Current information: \n"
for x, y in a.items():
if not isinstance(x, str):
current_information += f"{x}: {y}\n"
else:
current_information += f"{x.capitalize()}: {y}\n"
print(current_information)
def update_information(a):
while True:
key = input("Enter a key to update or type 'exit' to exit: ").lower()
if key == "exit":
break
if key.isdigit():
key = int(key)
if key in a:
value = input("Enter a value to update: ").lower()
if value.isdigit():
value = int(value)
a.update({key: value})
print(f"'{key}' and its value '{value}' were successfully updated!")
break
else:
print(f"'{key}' cannot be updated because it wasn't found!")
def delete_information(a):
while True:
key = input("Enter a key to delete or type 'exit' to exit: ").lower()
if key == "exit":
break
if key.isdigit():
key = int(key)
if key in a:
a.pop(key)
print(f"'{key}' has been deleted!")
break
else:
print(f"'{key}' cannot be deleted because it wasn't found!")
create_information(user_information)