1
+ import sqlite3 as sql
2
+
3
+ connect = sql .connect ('planner.db' )
4
+ cursor = connect .cursor ()
5
+
6
+ cursor .execute ("CREATE TABLE IF NOT EXISTS tasks (type TEXT, task TEXT, time REAL)" )
7
+
8
+ print ('Welcome to your planner!' )
9
+
10
+ choice = None
11
+ while choice != 3 :
12
+ print ('\n What would you like to do?' )
13
+ print ('1). View Tasks' )
14
+ print ('2). Edit Planner' )
15
+ print ('3). Quit' )
16
+ try :
17
+ choice = int (input ('-> ' ))
18
+ except ValueError :
19
+ print ('\n Not a valid number.' )
20
+
21
+ if choice == 1 :
22
+ cursor .execute ("SELECT * FROM tasks" )
23
+ print ('\n {:<15} {:<15} {:<15}' .format ('Type' , 'Task' , 'Time' ))
24
+
25
+ for task in cursor .fetchall ():
26
+ print ('{:<15} {:<15} {:<15}\n ' .format (task [0 ], task [1 ], task [2 ]))
27
+
28
+ if choice == 2 :
29
+ print ('\n Would you like to:' )
30
+ print ('1). Add' )
31
+ print ('2). Edit' )
32
+ print ('3). Delete' )
33
+ print ('4). Reset' )
34
+ print ('5). Go back' )
35
+ try :
36
+ choice = int (input ('-> ' ))
37
+ except ValueError :
38
+ print ('\n Not a valid number.' )
39
+
40
+ if choice == 1 :
41
+ task = input ('\n Task: ' )
42
+ type = input ('Type of task: ' )
43
+ time = float (input ('Time to complete in hours: ' ))
44
+ values = (type , task , time )
45
+ cursor .execute ("INSERT INTO tasks VALUES (?, ?, ?)" , values )
46
+ connect .commit ()
47
+
48
+ elif choice == 2 :
49
+ cursor .execute ("SELECT * FROM tasks" )
50
+ tasks = cursor .fetchall ()
51
+ print ('\n Which number task would you like to edit? ' )
52
+ for i , task in enumerate (tasks ):
53
+ print (f'{ i + 1 } . { task [1 ]} ' )
54
+ choice = int (input ('-> ' ))
55
+ task_name = tasks [choice - 1 ][1 ]
56
+ print ('\n Would you like to edit:' )
57
+ print ('1). Task' )
58
+ print ('2). Type' )
59
+ print ('3). Time' )
60
+ try :
61
+ choice = int (input ('-> ' ))
62
+ except ValueError :
63
+ print ('\n Not a valid number.' )
64
+ if choice == 1 :
65
+ task = input ('\n Task: ' )
66
+ values = (task , task_name )
67
+ cursor .execute ("UPDATE tasks SET task = ? WHERE task = ?" , values )
68
+ connect .commit ()
69
+ elif choice == 2 :
70
+ type = input ('Type of task: ' )
71
+ values = (type , task_name )
72
+ cursor .execute ("UPDATE tasks SET type = ? WHERE task = ?" , values )
73
+ connect .commit ()
74
+ elif choice == 3 :
75
+ choice = None
76
+ time = float (input ('Time to complete in hours: ' ))
77
+ values = (time , task_name )
78
+ cursor .execute ("UPDATE tasks SET time = ? WHERE task = ?" , values )
79
+ connect .commit ()
80
+ else :
81
+ print ('Not a valid number.' )
82
+
83
+
84
+
85
+
86
+
87
+ elif choice == 3 :
88
+ delete = int (input ('\n Which number item would you like to delete? ' ))
89
+ choice = None
90
+ elif choice == 4 :
91
+ verify = input ('\n Are you sure you want to reset the planner? (y/n) ' )
92
+ elif choice == 5 :
93
+ pass
94
+ else :
95
+ print ('Not a valid number.' )
96
+
97
+
98
+
99
+
100
+
0 commit comments