Day 31 Python for Coders Track Your Habits with Python! 📅 | Build a Habit Tracker App | EgniCode

Опубликовано: 28 Февраль 2026
на канале: EgniCode
537
13

🎯 Stay consistent and achieve your goals with Python! In this video, we build a Habit Tracker App that helps you log habits daily, track progress, and stay productive. Perfect for coding beginners and personal development enthusiasts!

💡 What You’ll Learn:

How to use JSON for storing data.
Leveraging the datetime module to track daily logs.
Building a functional app to boost your productivity.
🚀 Expand the Project:

Add streak counters to motivate consistency.
Build a GUI version using Tkinter.
Visualize progress with charts using Matplotlib.
📌 Resources to Get Started:
import json
from datetime import date

File to store habit data
habit_file = "habits.json"

Load habits from the file
def load_habits():
try:
with open(habit_file, "r") as file:
return json.load(file)
except FileNotFoundError:
return {}

Save habits to the file
def save_habits(habits):
with open(habit_file, "w") as file:
json.dump(habits, file, indent=4)

Add a new habit
def add_habit(habit):
habits = load_habits()
if habit not in habits:
habits[habit] = []
print(f"Added habit: '{habit}'")
else:
print(f"Habit '{habit}' already exists!")
save_habits(habits)

Log a habit for today
def log_habit(habit):
habits = load_habits()
today = str(date.today())
if habit in habits:
if today not in habits[habit]:
habits[habit].append(today)
print(f"Habit '{habit}' logged for today!")
else:
print(f"Habit '{habit}' already logged today.")
else:
print(f"Habit '{habit}' not found! Add it first.")
save_habits(habits)

View progress for all habits
def view_progress():
habits = load_habits()
if habits:
for habit, dates in habits.items():
print(f"Habit: {habit} - Logged {len(dates)} times")
print(f"Dates: {', '.join(dates)}")
else:
print("No habits found! Start by adding a new habit.")

if _name_ == "__main__":
print("📅 Welcome to the Habit Tracker!")
while True:
print("\n1. Add a new habit\n2. Log a habit\n3. View progress\n4. Exit")
choice = input("Choose an option: ")
if choice == "1":
habit = input("Enter the habit name: ").strip()
add_habit(habit)
elif choice == "2":
habit = input("Enter the habit to log: ").strip()
log_habit(habit)
elif choice == "3":
view_progress()
elif choice == "4":
print("Goodbye! Keep building great habits!")
break
else:
print("Invalid choice. Try again.")


How It Works:
Add Habit: Create a new habit that gets stored in a habits.json file.
Log Habit: Record the habit for today’s date.
View Progress: See how many times each habit has been completed along with the dates.
Data Storage: Habits and logs are saved in habits.json for persistent tracking.
How to Run:
Copy the code into a file named habit_tracker.py.
Run the script: python habit_tracker.py.
Follow the menu options to add, log, and track your habits.


Python JSON Docs
Python datetime Module
🔥 Trending Hashtags:
#picoftheday #naturephotography #bhfyp #trending #lifestyle #happy #viral #earth #beauty #italy #nyc #texas #losangeles #music #like#土曜はカニする箱根駅伝#global #music #love #worldwide #international #business #instagram #explore #world #india #viral #follow #hiphop #usa #fashion #explorepage #travel #art #trending #london #covid #africa #nature #marketing #newyork #entrepreneur #photography #europe #instagood #newsDigitalMarketing, #TechNews, #SelfCareSunday, #Innovation, #FitnessGoals, #FoodieFriday, #MondayMotivation, #ThrowbackThursday, #FashionTrends, and #EntrepreneurLife.
#Python #HabitTracker #EgniCode#Python #Coding #Programming #TechTutorial #PythonTips #PythonProjects #ObjectOrientedProgramming #LearnPython #Shorts #CodingForBeginners #TechShorts #YouTubeShorts #Trending #FYP #Education #ProgrammingBasics #TechExplained #PythonCoding #tech #technology #gadgets #instatech #google #electronics #gaming #computer #geek #apple #digital #technews #code #innovation #programmers #techno #techie #samsung #software #android #gadget #business #gamingsetup #programmer #coder
#PythonProjects #LearnToCode #StayConsistent #CodingForBeginners #PythonForLife #SelfImprovement #CodeWithPurpose #ProductivityTools #TechForGood #Trending #FYP #Shorts