Skip to content

Commit 0ea4bdc

Browse files
authored
Create simple_study_buddy.py
1 parent 3a989e0 commit 0ea4bdc

File tree

1 file changed

+163
-0
lines changed

1 file changed

+163
-0
lines changed

simple_study_buddy.py

Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
"""
2+
Simple Study Buddy - A simplified Python learning application
3+
"""
4+
5+
from dataclasses import dataclass
6+
from typing import Dict, List
7+
from rich.console import Console
8+
from rich.panel import Panel
9+
from rich.prompt import Prompt, IntPrompt
10+
from rich.table import Table
11+
from rich.markdown import Markdown
12+
import json
13+
14+
@dataclass
15+
class Exercise:
16+
"""Represents a single exercise"""
17+
title: str
18+
description: str
19+
hint: str
20+
solution: str
21+
difficulty: int
22+
23+
@dataclass
24+
class StudyProgress:
25+
"""Tracks user's learning progress"""
26+
user_name: str
27+
level: str
28+
completed_exercises: List[str]
29+
current_streak: int
30+
total_exercises_attempted: int
31+
start_date: str
32+
achievements: List[str]
33+
34+
class PythonStudyBuddy:
35+
"""Main study buddy application class"""
36+
37+
def __init__(self, custom_exercises: Dict[str, List[Exercise]] = None, custom_progress: StudyProgress = None):
38+
self.console = Console()
39+
self.exercises = custom_exercises or {}
40+
self.progress = custom_progress or StudyProgress(
41+
user_name="Student",
42+
level="beginner",
43+
completed_exercises=[],
44+
current_streak=0,
45+
total_exercises_attempted=0,
46+
start_date="",
47+
achievements=[]
48+
)
49+
50+
def display_welcome(self):
51+
"""Display welcome message"""
52+
welcome_text = f"""
53+
# 🐍 Python Study Buddy
54+
55+
Welcome, **{self.progress.user_name}**!
56+
Ready to practice Python at the **{self.progress.level}** level?
57+
58+
Current Streak: 🔥 {self.progress.current_streak} days
59+
Exercises Completed: ✅ {len(self.progress.completed_exercises)}
60+
"""
61+
self.console.print(Panel(Markdown(welcome_text), border_style="blue"))
62+
63+
def display_exercise(self, exercise: Exercise):
64+
"""Display a single exercise"""
65+
self.console.print(f"\n[bold cyan]📝 {exercise.title}[/bold cyan]")
66+
self.console.print(f"[yellow]Difficulty: {'⭐' * exercise.difficulty}[/yellow]\n")
67+
self.console.print(Panel(exercise.description, title="Description", border_style="green"))
68+
69+
def get_exercise_choice(self) -> Exercise:
70+
"""Let user choose an exercise"""
71+
exercises_list = self.exercises.get(self.progress.level, [])
72+
73+
if not exercises_list:
74+
self.console.print("[red]No exercises available for your level![/red]")
75+
return None
76+
77+
# Display available exercises
78+
table = Table(title=f"Available {self.progress.level.title()} Exercises")
79+
table.add_column("No.", style="cyan", width=4)
80+
table.add_column("Title", style="magenta")
81+
table.add_column("Difficulty", style="yellow")
82+
table.add_column("Status", style="green")
83+
84+
for idx, exercise in enumerate(exercises_list, 1):
85+
status = "✅ Completed" if exercise.title in self.progress.completed_exercises else "📝 Not started"
86+
table.add_row(
87+
str(idx),
88+
exercise.title,
89+
"⭐" * exercise.difficulty,
90+
status
91+
)
92+
93+
self.console.print(table)
94+
95+
# Get user choice
96+
choice = IntPrompt.ask(
97+
"\n[bold]Choose an exercise (number)[/bold]",
98+
default=1,
99+
choices=[str(i) for i in range(1, len(exercises_list) + 1)]
100+
)
101+
102+
return exercises_list[choice - 1]
103+
104+
def practice_exercise(self, exercise: Exercise):
105+
"""Practice a single exercise"""
106+
self.display_exercise(exercise)
107+
108+
# Show hint option
109+
show_hint = Prompt.ask("\n[yellow]Need a hint? (y/n)[/yellow]", default="n")
110+
if show_hint.lower() == 'y':
111+
self.console.print(Panel(f"💡 Hint: {exercise.hint}", border_style="yellow"))
112+
113+
# Get user's solution
114+
self.console.print("\n[bold]Write your solution:[/bold]")
115+
user_solution = Prompt.ask(">>> ")
116+
117+
# Show solution
118+
show_solution = Prompt.ask("\n[yellow]Ready to see the solution? (y/n)[/yellow]", default="y")
119+
if show_solution.lower() == 'y':
120+
self.console.print(Panel(
121+
f"✨ Solution:\n{exercise.solution}",
122+
title="Solution",
123+
border_style="green"
124+
))
125+
126+
# Mark as completed
127+
completed = Prompt.ask("\n[bold]Did you complete this exercise? (y/n)[/bold]", default="y")
128+
if completed.lower() == 'y' and exercise.title not in self.progress.completed_exercises:
129+
self.progress.completed_exercises.append(exercise.title)
130+
self.progress.total_exercises_attempted += 1
131+
self.console.print("[green]✅ Great job! Exercise marked as completed![/green]")
132+
133+
def run_study_session(self):
134+
"""Run the main study session"""
135+
self.display_welcome()
136+
137+
while True:
138+
exercise = self.get_exercise_choice()
139+
if not exercise:
140+
break
141+
142+
self.practice_exercise(exercise)
143+
144+
# Ask if user wants to continue
145+
continue_session = Prompt.ask(
146+
"\n[bold]Continue with another exercise? (y/n)[/bold]",
147+
default="y"
148+
)
149+
if continue_session.lower() != 'y':
150+
break
151+
152+
# Show summary
153+
self.console.print(Panel(
154+
f"""
155+
[bold green]Session Summary[/bold green]
156+
Exercises Completed: {len(self.progress.completed_exercises)}
157+
Total Attempts: {self.progress.total_exercises_attempted}
158+
159+
Keep up the great work! 🎉
160+
""",
161+
border_style="green"
162+
))
163+

0 commit comments

Comments
 (0)