-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfortest.py
90 lines (74 loc) · 2.88 KB
/
fortest.py
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
import sqlite3
connection = sqlite3.connect('students.db')
cursor = connection.cursor()
cursor.execute('''
CREATE TABLE IF NOT EXISTS students (
name TEXT,
score INTEGER
)
''')
while True:
name = input("ples enter name : ")
score = int(input("enter score :"))
if name.lower() == 'exit':
break
cursor.execute("""INSERT INTO students (name, score) VALUES (?, ?)""", (name, score))
connection.commit()
print("\n show deta :")
cursor.execute("""SELECT * FROM students""")
for row in cursor.fetchall():
print(f" name: {row[0]} | score: {row[1]}")
while True:
enter=input("do you want search,updet,delet , sort of score just writ wich one :")
if enter=="updet":
name=input("wich one just wrut name for update :")
ask=input("do you want edit name y/n:")
if ask=="y":
newneame=input("writ new name :")
cursor.execute("""UPDATE students SET name=? WHERE name=?""",(newneame,name))
connection.commit()
print("\n show deta :")
cursor.execute("""SELECT * FROM students""")
for row in cursor.fetchall():
print(f" name: {row[0]} | score: {row[1]}")
else:
score=int(input("new score : "))
cursor.execute("""UPDATE students SET score=? WHERE name=?""",(score,name))
connection.commit()
print("\n show deta :")
cursor.execute("""SELECT * FROM students""")
for row in cursor.fetchall():
print(f" name: {row[0]} | score: {row[1]}")
if enter=="delet":
name = input("Enter name for deletion: ")
sql = "DELETE FROM students WHERE name = ?"
name_tuple = (name,)
cursor.execute(sql, name_tuple)
connection.commit()
print("\n show deta :")
cursor.execute("""SELECT * FROM students""")
for row in cursor.fetchall():
print(f" name: {row[0]} | score: {row[1]}")
print(name_tuple,"is deleted ")
if enter=="search":
name=input("name of student : ")
sql = "SELECT * FROM students WHERE name LIKE ?"
cursor.execute(sql, (name,))
# Fetch the search results
search_results = cursor.fetchall()
# Check if any results were found
if search_results:
print("\nSearch Results:")
for row in search_results:
print(f"Name: {row[0]} | Score: {row[1]}")
else:
print("No student found with the given name.")
if enter == "sort":
print("\nShow sorted data:")
cursor.execute("""SELECT * FROM students ORDER BY score DESC""")
for row in cursor.fetchall():
print(f"Name: {row[0]} | Score: {row[1]}")
if enter=="no":
print(" so bay bye")
break
connection.close()