Skip to content

Commit 2ae9f20

Browse files
Skills App
1 parent 18e7882 commit 2ae9f20

File tree

1 file changed

+68
-0
lines changed

1 file changed

+68
-0
lines changed

5- Skills app.py

+68
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,15 @@
2424

2525
# insert data
2626
try:
27+
2728
IDs_list = [1, 2, 3, 4, 5]
29+
2830
for Id in IDs_list:
31+
2932
cr.execute(F"insert into IDs (user_id) values ('{Id}')")
3033

3134
except:
35+
3236
pass
3337

3438

@@ -38,11 +42,13 @@
3842

3943
# Fetch Data
4044
cr.execute(f"select user_id from IDs where user_id = '{u_id}'")
45+
4146
IDs = cr.fetchone()
4247

4348

4449
# database password
4550
password = ['skills_database@12345']
51+
4652
tries = 5
4753

4854

@@ -73,6 +79,7 @@ def start_the_app():
7379

7480
# Commit and close database
7581
def commit_and_close():
82+
7683
db.commit()
7784
db.close()
7885

@@ -82,43 +89,74 @@ def commit_and_close():
8289
# ------------------
8390

8491
def show_all_skills():
92+
8593
# show skills
8694
cr.execute(f"select * from skills where user_id = '{u_id}'")
95+
8796
results = cr.fetchall()
97+
8898
print(f"You have '{len(results)}' skills")
99+
89100
for row in results:
101+
90102
print(f"- Skill name => '{row[1]}', Skill progress => '{row[2]}'%")
91103

104+
92105
def add_new_skill():
106+
93107
# insert data
94108
skill = input("Write Skill Name: ").strip().capitalize()
109+
95110
cr.execute(f"select skill_name from skills where skill_name = '{skill}' and user_id = '{u_id}'")
111+
96112
results = cr.fetchone()
113+
97114
if results == None:
115+
98116
progress = input("Write Skill Progress: ").strip()
117+
99118
cr.execute(f"insert into skills (user_id, skill_name, skill_progress) values ('{u_id}', '{skill}', '{progress}')")
119+
100120
print(f"'{skill}' is added")
121+
101122
else:
123+
102124
print(f"This skill '{skill}' is already exists")
125+
103126
U_input = input("Do you want to update its progress? Yes or No ").strip().lower()
127+
104128
if U_input == "yes":
129+
105130
new_progress = input("Write the new Skill Progress: ").strip()
131+
106132
cr.execute(f"update skills set skill_progress = '{new_progress}' where skill_name = '{skill}' and user_id = '{u_id}'")
133+
107134
print(f"'{skill}' progress is updated")
135+
108136
else:
137+
109138
commit_and_close()
110139

140+
111141
def delete_skill():
142+
112143
# delete data
113144
skill = input("Write Skill Name: ").strip().capitalize()
145+
114146
cr.execute(f"delete from skills where skill_name = '{skill}' and user_id = '{u_id}'")
147+
115148
print(f"'{skill}' is deleted")
116149

150+
117151
def update_skill_progress():
152+
118153
# update data
119154
skill = input("Write the Skill Name that you want to update its progress: ").strip().capitalize()
155+
120156
new_progress = input("Write the new Skill Progress: ").strip()
157+
121158
cr.execute(f"update skills set skill_progress = '{new_progress}' where skill_name = '{skill}' and user_id = '{u_id}'")
159+
122160
print(f"'{skill}' progress is updated")
123161

124162

@@ -128,76 +166,106 @@ def update_skill_progress():
128166
if user_input in commands_list:
129167

130168
if user_input == "s":
169+
131170
show_all_skills()
132171
commit_and_close()
133172

134173
elif user_input == "a":
174+
135175
add_new_skill()
136176
commit_and_close()
137177

138178
elif user_input == "d":
179+
139180
delete_skill()
140181
commit_and_close()
141182

142183
elif user_input == "u":
184+
143185
update_skill_progress()
144186
commit_and_close()
145187

146188
else:
189+
147190
commit_and_close()
148191
print("App is closed")
149192

193+
150194
else:
195+
151196
print(f"Sorry, Your command '{user_input}' not found")
152197

153198

154199
# check if the u_id is present
155200
if IDs != None:
201+
156202
print(f"Welcome {u_name}!")
203+
157204
start_the_app()
158205

159206
else:
207+
160208
print(f"Sorry, You have no access to this database")
161209

162210

163211
# check if the user want to have access or no
164212
ques = input("Do you want to have access to this database? Yes or No ").strip().lower()
165213

166214
if ques == 'yes':
215+
167216
user_password = input("Please enter your password. ").strip()
168217

169218
# check password
170219
# if password is right
171220
if user_password in password:
221+
172222
cr.execute(f"insert into IDs (user_id) values ('{u_id}')")
223+
173224
print(f"Welcome {u_name}!")
225+
174226
print("Now you have access to this database")
227+
175228
start_the_app()
176229

177230
# if password is wrong
178231
else:
232+
179233
while user_password not in password:
234+
180235
tries -= 1
181236

182237
if tries == 0:
238+
183239
print('Wrong password, Last chance left')
240+
184241
elif tries == 1:
242+
185243
print('Wrong password, 1 chance left')
244+
186245
else:
246+
187247
print(f'Wrong password, {tries} chances left')
188248

189249
user_password = input("Enter your password. ")
190250

191251
if tries == 0 and user_password not in password:
252+
192253
print('All chances are finished!')
254+
193255
print("You have no access to this database.")
256+
194257
break
195258

196259
else:
260+
197261
cr.execute(f"insert into IDs (user_id) values ('{u_id}')")
262+
198263
print(f"Welcome {u_name}!")
264+
199265
print("Now you have access to this database")
266+
200267
start_the_app()
201268

202269
if ques == 'no':
270+
203271
print("You Are Not Added.")

0 commit comments

Comments
 (0)