-
Notifications
You must be signed in to change notification settings - Fork 464
Expand file tree
/
Copy pathhabit_tracker.py
More file actions
39 lines (36 loc) · 1.03 KB
/
Copy pathhabit_tracker.py
File metadata and controls
39 lines (36 loc) · 1.03 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
import json
import datetime
habits={
1:"Drink water",
2:"Walk the dog",
3:"Run",
4:"Read a book"
}
try:
with open("data.json", "r") as f:
data = json.load(f)
except FileNotFoundError:
data = {}
x = datetime.datetime.now()
today_date= str(str(x.year)+ "-"+str(x.month) +"-"+ str(x.day))
if today_date not in data:
data[today_date] = {}
def tracker():
completed_habits=0
for habit_id in habits:
user_answer = input(f"{habits[habit_id]} ? (y/n)").lower()
habit_name= habits[habit_id]
if user_answer == "y":
value = True
completed_habits +=1
elif user_answer == "n":
value = False
else:
print("Incorrect input!")
return
data[today_date][habit_name] = value
status= "Amazing job !" if completed_habits == len(habits) else "Keep it going !"
print(f"You have completed {completed_habits}/{len(habits)} of your habits! {status}")
tracker()
with open('data.json', 'w') as f:
json.dump(data, f)