-
Notifications
You must be signed in to change notification settings - Fork 199
Expand file tree
/
Copy pathsimple_study_buddy.py
More file actions
163 lines (135 loc) Β· 5.56 KB
/
simple_study_buddy.py
File metadata and controls
163 lines (135 loc) Β· 5.56 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
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
"""
Simple Study Buddy - A simplified Python learning application
"""
from dataclasses import dataclass
from typing import Dict, List
from rich.console import Console
from rich.panel import Panel
from rich.prompt import Prompt, IntPrompt
from rich.table import Table
from rich.markdown import Markdown
import json
@dataclass
class Exercise:
"""Represents a single exercise"""
title: str
description: str
hint: str
solution: str
difficulty: int
@dataclass
class StudyProgress:
"""Tracks user's learning progress"""
user_name: str
level: str
completed_exercises: List[str]
current_streak: int
total_exercises_attempted: int
start_date: str
achievements: List[str]
class PythonStudyBuddy:
"""Main study buddy application class"""
def __init__(self, custom_exercises: Dict[str, List[Exercise]] = None, custom_progress: StudyProgress = None):
self.console = Console()
self.exercises = custom_exercises or {}
self.progress = custom_progress or StudyProgress(
user_name="Student",
level="beginner",
completed_exercises=[],
current_streak=0,
total_exercises_attempted=0,
start_date="",
achievements=[]
)
def display_welcome(self):
"""Display welcome message"""
welcome_text = f"""
# π Python Study Buddy
Welcome, **{self.progress.user_name}**!
Ready to practice Python at the **{self.progress.level}** level?
Current Streak: π₯ {self.progress.current_streak} days
Exercises Completed: β
{len(self.progress.completed_exercises)}
"""
self.console.print(Panel(Markdown(welcome_text), border_style="blue"))
def display_exercise(self, exercise: Exercise):
"""Display a single exercise"""
self.console.print(f"\n[bold cyan]π {exercise.title}[/bold cyan]")
self.console.print(f"[yellow]Difficulty: {'β' * exercise.difficulty}[/yellow]\n")
self.console.print(Panel(exercise.description, title="Description", border_style="green"))
def get_exercise_choice(self) -> Exercise:
"""Let user choose an exercise"""
exercises_list = self.exercises.get(self.progress.level, [])
if not exercises_list:
self.console.print("[red]No exercises available for your level![/red]")
return None
# Display available exercises
table = Table(title=f"Available {self.progress.level.title()} Exercises")
table.add_column("No.", style="cyan", width=4)
table.add_column("Title", style="magenta")
table.add_column("Difficulty", style="yellow")
table.add_column("Status", style="green")
for idx, exercise in enumerate(exercises_list, 1):
status = "β
Completed" if exercise.title in self.progress.completed_exercises else "π Not started"
table.add_row(
str(idx),
exercise.title,
"β" * exercise.difficulty,
status
)
self.console.print(table)
# Get user choice
choice = IntPrompt.ask(
"\n[bold]Choose an exercise (number)[/bold]",
default=1,
choices=[str(i) for i in range(1, len(exercises_list) + 1)]
)
return exercises_list[choice - 1]
def practice_exercise(self, exercise: Exercise):
"""Practice a single exercise"""
self.display_exercise(exercise)
# Show hint option
show_hint = Prompt.ask("\n[yellow]Need a hint? (y/n)[/yellow]", default="n")
if show_hint.lower() == 'y':
self.console.print(Panel(f"π‘ Hint: {exercise.hint}", border_style="yellow"))
# Get user's solution
self.console.print("\n[bold]Write your solution:[/bold]")
user_solution = Prompt.ask(">>> ")
# Show solution
show_solution = Prompt.ask("\n[yellow]Ready to see the solution? (y/n)[/yellow]", default="y")
if show_solution.lower() == 'y':
self.console.print(Panel(
f"β¨ Solution:\n{exercise.solution}",
title="Solution",
border_style="green"
))
# Mark as completed
completed = Prompt.ask("\n[bold]Did you complete this exercise? (y/n)[/bold]", default="y")
if completed.lower() == 'y' and exercise.title not in self.progress.completed_exercises:
self.progress.completed_exercises.append(exercise.title)
self.progress.total_exercises_attempted += 1
self.console.print("[green]β
Great job! Exercise marked as completed![/green]")
def run_study_session(self):
"""Run the main study session"""
self.display_welcome()
while True:
exercise = self.get_exercise_choice()
if not exercise:
break
self.practice_exercise(exercise)
# Ask if user wants to continue
continue_session = Prompt.ask(
"\n[bold]Continue with another exercise? (y/n)[/bold]",
default="y"
)
if continue_session.lower() != 'y':
break
# Show summary
self.console.print(Panel(
f"""
[bold green]Session Summary[/bold green]
Exercises Completed: {len(self.progress.completed_exercises)}
Total Attempts: {self.progress.total_exercises_attempted}
Keep up the great work! π
""",
border_style="green"
))