Skip to content

Commit be7965d

Browse files
committed
fixing naming and add run file.
1 parent c1cf9cc commit be7965d

File tree

7 files changed

+228
-38
lines changed

7 files changed

+228
-38
lines changed

.vsocde/mcp.json renamed to .vscode/mcp.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
],
44
"servers": {
55
"learnpython-mcp": {
6-
"command": "/opt/anaconda3/bin/uv",
6+
"command": "/home/codespace/.python/current/bin/uv",
77
"args": [
88
"--directory",
99
".",

.vsocde/study_progress.json

Lines changed: 0 additions & 11 deletions
This file was deleted.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ mcp-env\Scripts\activate
129129
### 6. Install packages
130130

131131
```bash
132-
uv sync
132+
uv sync --active
133133
```
134134

135135
### 6. Walk through the core concepts in the terminal

beginner_exercises.json

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,37 @@
11
[
22
{
3-
"title": "Age Checker",
4-
"description": "Write a program that asks the user for their age and tells them if they are a child (under 13), teenager (13-17), or adult (18+).",
5-
"hint": "Use input() to get the age, convert it to an integer with int(), and use if/elif/else statements to check the different age ranges.",
6-
"solution": "age = int(input('Enter your age: '))\nif age < 13:\n print('You are a child')\nelif age <= 17:\n print('You are a teenager')\nelse:\n print('You are an adult')",
3+
"title": "Age Classifier",
4+
"description": "Write a program that asks for a person's age and classifies them as 'child' (under 13), 'teenager' (13-19), 'adult' (20-64), or 'senior' (65 and above).",
5+
"hint": "Use if/elif/else statements to check age ranges. Remember that elif means 'else if'.",
6+
"solution": "age = int(input('Enter your age: '))\nif age < 13:\n print('You are a child')\nelif age <= 19:\n print('You are a teenager')\nelif age <= 64:\n print('You are an adult')\nelse:\n print('You are a senior')",
77
"difficulty": 2
88
},
99
{
10-
"title": "Grade Calculator",
11-
"description": "Create a program that takes a test score (0-100) and prints the corresponding letter grade: A (90-100), B (80-89), C (70-79), D (60-69), F (below 60).",
12-
"hint": "Use if/elif/else statements to check score ranges. Remember that >= and <= help define ranges.",
13-
"solution": "score = int(input('Enter your test score: '))\nif score >= 90:\n print('Grade: A')\nelif score >= 80:\n print('Grade: B')\nelif score >= 70:\n print('Grade: C')\nelif score >= 60:\n print('Grade: D')\nelse:\n print('Grade: F')",
14-
"difficulty": 2
10+
"title": "Number Guessing Game",
11+
"description": "Create a simple number guessing game where the computer picks a number between 1 and 10, and the user has 3 attempts to guess it correctly.",
12+
"hint": "Use a for loop with range(3) for attempts. Use if statements to check if the guess is correct, too high, or too low.",
13+
"solution": "import random\nsecret_number = random.randint(1, 10)\nprint('I\\'m thinking of a number between 1 and 10. You have 3 guesses!')\n\nfor attempt in range(3):\n guess = int(input(f'Attempt {attempt + 1}: Enter your guess: '))\n if guess == secret_number:\n print('Congratulations! You guessed it!')\n break\n elif guess < secret_number:\n print('Too low!')\n else:\n print('Too high!')\nelse:\n print(f'Sorry, the number was {secret_number}')",
14+
"difficulty": 3
1515
},
1616
{
17-
"title": "Number Comparison",
18-
"description": "Write a program that asks for two numbers and tells the user which number is larger, or if they are equal.",
19-
"hint": "Use input() to get two numbers, convert them to integers, then use if/elif/else to compare them.",
20-
"solution": "num1 = int(input('Enter first number: '))\nnum2 = int(input('Enter second number: '))\nif num1 > num2:\n print(f'{num1} is larger than {num2}')\nelif num2 > num1:\n print(f'{num2} is larger than {num1}')\nelse:\n print('Both numbers are equal')",
17+
"title": "Multiplication Table",
18+
"description": "Write a program that prints the multiplication table for a given number from 1 to 10 using a for loop.",
19+
"hint": "Use a for loop with range(1, 11) to multiply the input number by each value from 1 to 10.",
20+
"solution": "number = int(input('Enter a number for multiplication table: '))\nprint(f'Multiplication table for {number}:')\nfor i in range(1, 11):\n result = number * i\n print(f'{number} x {i} = {result}')",
2121
"difficulty": 1
2222
},
2323
{
24-
"title": "Even or Odd",
25-
"description": "Create a program that asks the user for a number and tells them if it's even or odd.",
26-
"hint": "Use the modulo operator (%) to check if a number is divisible by 2. If number % 2 == 0, it's even.",
27-
"solution": "number = int(input('Enter a number: '))\nif number % 2 == 0:\n print(f'{number} is even')\nelse:\n print(f'{number} is odd')",
28-
"difficulty": 1
24+
"title": "Even or Odd Counter",
25+
"description": "Create a program that asks the user to enter numbers until they enter 0. Count and display how many even and odd numbers were entered.",
26+
"hint": "Use a while loop that continues until the user enters 0. Use the modulo operator (%) to check if a number is even or odd.",
27+
"solution": "even_count = 0\nodd_count = 0\n\nprint('Enter numbers (enter 0 to stop):')\nwhile True:\n number = int(input('Enter a number: '))\n if number == 0:\n break\n elif number % 2 == 0:\n even_count += 1\n else:\n odd_count += 1\n\nprint(f'Even numbers entered: {even_count}')\nprint(f'Odd numbers entered: {odd_count}')",
28+
"difficulty": 3
2929
},
3030
{
31-
"title": "Weather Advisor",
32-
"description": "Write a program that asks for the temperature and gives clothing advice: 'Wear a coat' (below 60\u00b0F), 'Wear a sweater' (60-75\u00b0F), or 'Wear light clothes' (above 75\u00b0F).",
33-
"hint": "Get the temperature as input, convert to integer, and use if/elif/else to check temperature ranges.",
34-
"solution": "temp = int(input('Enter temperature in Fahrenheit: '))\nif temp < 60:\n print('Wear a coat')\nelif temp <= 75:\n print('Wear a sweater')\nelse:\n print('Wear light clothes')",
31+
"title": "Grade Calculator",
32+
"description": "Write a program that calculates the average of 5 test scores and assigns a letter grade: A (90-100), B (80-89), C (70-79), D (60-69), F (below 60).",
33+
"hint": "Use a for loop to collect 5 scores, calculate the average, then use if/elif statements to assign the letter grade.",
34+
"solution": "total_score = 0\nprint('Enter 5 test scores:')\n\nfor i in range(5):\n score = float(input(f'Enter score {i + 1}: '))\n total_score += score\n\naverage = total_score / 5\nprint(f'Average score: {average:.1f}')\n\nif average >= 90:\n grade = 'A'\nelif average >= 80:\n grade = 'B'\nelif average >= 70:\n grade = 'C'\nelif average >= 60:\n grade = 'D'\nelse:\n grade = 'F'\n\nprint(f'Letter grade: {grade}')",
3535
"difficulty": 2
3636
}
37-
]
37+
]

part2-study-buddy.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,13 @@ uv sync
5353

5454
#### Configure Python Learning MCP
5555
- Install and configure a Python Learning MCP server in VS Code
56+
- to get the path to uv, run `which uv`
5657

5758
Open the **.vscode** folder and make sure you see a file named **mcp.json** with the following content:
5859

5960
```json
6061
"learnpython-mcp": {
61-
"command": "/opt/anaconda3/bin/uv",
62+
"command": "{path-to-uv}",
6263
"args": [
6364
"--directory",
6465
".",

run_study_buddy.py

Lines changed: 200 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,200 @@
1+
"""
2+
Run the Python Study Buddy in a terminal
3+
This script creates a study buddy instance based on command line arguments.
4+
"""
5+
6+
import sys
7+
import os
8+
from datetime import datetime
9+
10+
def main():
11+
"""Run the study buddy using command line arguments."""
12+
if len(sys.argv) < 3:
13+
print("Error: Missing required arguments.")
14+
print("Usage: python run_study_buddy.py <username> <level>")
15+
sys.exit(1)
16+
17+
username = sys.argv[1]
18+
level = sys.argv[2]
19+
20+
try:
21+
# Import the necessary modules
22+
from simple_study_buddy import PythonStudyBuddy, StudyProgress
23+
24+
print(f"\n{'=' * 60}")
25+
print(f"🐍 Python Study Buddy - Terminal Session")
26+
print(f"{'=' * 60}")
27+
print(f"👤 Username: {username}")
28+
print(f"📊 Level: {level}")
29+
print(f"📅 Session Date: {datetime.now().strftime('%Y-%m-%d %H:%M')}")
30+
print(f"{'=' * 60}\n")
31+
32+
# Load the exercise data based on the level
33+
exercise_data = load_exercises(level)
34+
35+
if not exercise_data or level not in exercise_data or not exercise_data[level]:
36+
print(f"\n⚠️ Warning: No {level} exercises found. Falling back to default exercises.")
37+
38+
# Create user progress
39+
user_progress = StudyProgress(
40+
user_name=username,
41+
level=level,
42+
completed_exercises=[],
43+
current_streak=0,
44+
total_exercises_attempted=0,
45+
start_date=datetime.now().isoformat(),
46+
achievements=[]
47+
)
48+
49+
# Create the study buddy instance
50+
study_buddy = PythonStudyBuddy(
51+
custom_exercises=exercise_data,
52+
custom_progress=user_progress
53+
)
54+
55+
# Print welcome message
56+
print(f"\n🚀 Starting Python Study Buddy session for {username} at {level} level!\n")
57+
58+
# Run the study buddy
59+
study_buddy.run_study_session()
60+
61+
print("\nSession completed. Thanks for studying Python!")
62+
63+
except Exception as e:
64+
print(f"\n❌ Error: Failed to run study buddy: {str(e)}")
65+
sys.exit(1)
66+
67+
def load_exercises(level):
68+
"""Load exercises for the given level."""
69+
import json
70+
import os
71+
from simple_study_buddy import Exercise
72+
73+
exercises = {}
74+
exercise_files_found = False
75+
76+
# First, look for specific level exercise file (e.g., beginner_exercises.json)
77+
try:
78+
level_file = f"{level}_exercises.json"
79+
if os.path.exists(level_file):
80+
print(f"📚 Loading exercises from {level_file}...")
81+
with open(level_file, 'r') as f:
82+
exercise_data = json.load(f)
83+
exercises[level] = []
84+
85+
for ex in exercise_data:
86+
exercises[level].append(Exercise(
87+
title=ex['title'],
88+
description=ex['description'],
89+
hint=ex['hint'],
90+
solution=ex['solution'],
91+
difficulty=ex['difficulty']
92+
))
93+
print(f"✅ Loaded {len(exercises[level])} exercises for {level} level!")
94+
exercise_files_found = True
95+
except Exception as e:
96+
print(f"❌ Could not load {level}_exercises.json: {e}")
97+
98+
# If specific level file not found, look for any exercise files
99+
if not exercise_files_found:
100+
try:
101+
# Look for exercise files in the current directory
102+
exercise_files = [f for f in os.listdir() if f.endswith('_exercises.json')]
103+
104+
if exercise_files:
105+
print(f"📚 Found {len(exercise_files)} exercise files.")
106+
107+
for file in exercise_files:
108+
with open(file, 'r') as f:
109+
try:
110+
exercise_data = json.load(f)
111+
level_key = file.split('_')[0] # Get the level from filename
112+
if level_key not in exercises:
113+
exercises[level_key] = []
114+
115+
for ex in exercise_data:
116+
exercises[level_key].append(Exercise(
117+
title=ex['title'],
118+
description=ex['description'],
119+
hint=ex['hint'],
120+
solution=ex['solution'],
121+
difficulty=ex['difficulty']
122+
))
123+
print(f"✅ Loaded {len(exercises[level_key])} exercises for {level_key} level!")
124+
exercise_files_found = True
125+
except:
126+
print(f"❌ Could not parse {file}")
127+
except Exception as e:
128+
print(f"❌ Error loading exercises from files: {e}")
129+
130+
# If no exercises found, provide fallback exercises
131+
if not exercise_files_found or level not in exercises or not exercises[level]:
132+
print("ℹ️ No appropriate exercises found. Creating default exercises...")
133+
return create_default_exercises()
134+
135+
return exercises
136+
137+
def create_default_exercises():
138+
"""Create default exercises as a fallback."""
139+
from simple_study_buddy import Exercise
140+
141+
return {
142+
"beginner": [
143+
Exercise(
144+
title="Hello Variables",
145+
description="Create a variable called `name` and assign your name to it. Then print 'Hello, ' followed by your name.",
146+
hint="Use the print() function and string concatenation with '+' or f-strings to combine text.",
147+
solution='name = "Marlene"\nprint("Hello, " + name)\n# Or using f-strings:\n# print(f"Hello, {name}")',
148+
difficulty=1
149+
),
150+
Exercise(
151+
title="Basic Data Types",
152+
description="Create four variables: an integer called `age` with value 25, a float called `height` with value 1.75, a boolean called `is_student` with value True, and a string called `favorite_color` with a color of your choice. Print each variable on a separate line with a description.",
153+
hint="Make sure to use the correct data type for each variable. Use print() with descriptive text.",
154+
solution='age = 25\nheight = 1.75\nis_student = True\nfavorite_color = "blue"\n\nprint("Age:", age)\nprint("Height:", height)\nprint("Is student?", is_student)\nprint("Favorite color:", favorite_color)',
155+
difficulty=2
156+
),
157+
Exercise(
158+
title="Type Conversion",
159+
description='Create a variable `user_input` with the string value "42". Convert it to an integer, multiply it by 2, and print the result.',
160+
hint="Use the int() function to convert a string to an integer.",
161+
solution='user_input = "42"\nconverted_number = int(user_input)\nresult = converted_number * 2\nprint(result)',
162+
difficulty=2
163+
),
164+
Exercise(
165+
title="Basic Math Operations",
166+
description="Create two variables: `x` with value 10 and `y` with value 3. Calculate and print the following operations: addition, subtraction, multiplication, division, integer division, modulus, and exponentiation of these two variables.",
167+
hint="Python uses standard math operators: +, -, *, /, //, %, and ** for exponentiation.",
168+
solution="x = 10\ny = 3\n\nprint(\"Addition:\", x + y)\nprint(\"Subtraction:\", x - y)\nprint(\"Multiplication:\", x * y)\nprint(\"Division:\", x / y)\nprint(\"Integer Division:\", x // y)\nprint(\"Modulus:\", x % y)\nprint(\"Exponentiation:\", x ** y)",
169+
difficulty=3
170+
),
171+
Exercise(
172+
title="String Operations",
173+
description="Create a variable `first_name` with your first name and `last_name` with your last name. Combine them to create a `full_name` variable. Then print the full name, the length of your full name, and your full name in all uppercase letters.",
174+
hint="Use string concatenation to combine strings and the len() function to get string length. The upper() method converts a string to uppercase.",
175+
solution='first_name = "John"\nlast_name = "Doe"\nfull_name = first_name + " " + last_name\n\nprint("Full name:", full_name)\nprint("Length of full name:", len(full_name))\nprint("Uppercase full name:", full_name.upper())',
176+
difficulty=3
177+
)
178+
],
179+
"intermediate": [
180+
Exercise(
181+
title="List Comprehension",
182+
description="Create a list of squares for numbers 1-10 using list comprehension",
183+
hint="Use the syntax: [expression for item in range()]",
184+
solution="squares = [x**2 for x in range(1, 11)]\nprint(squares)",
185+
difficulty=3
186+
)
187+
],
188+
"advanced": [
189+
Exercise(
190+
title="Decorator Pattern",
191+
description="Create a decorator that times how long a function takes to run",
192+
hint="Use time.time() before and after the function call",
193+
solution="import time\nfrom functools import wraps\n\ndef timer(func):\n @wraps(func)\n def wrapper(*args, **kwargs):\n start = time.time()\n result = func(*args, **kwargs)\n end = time.time()\n print(f'{func.__name__} took {end-start:.4f} seconds')\n return result\n return wrapper",
194+
difficulty=5
195+
)
196+
]
197+
}
198+
199+
if __name__ == "__main__":
200+
main()

study_progress.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@
88
"total_exercises_attempted": 1,
99
"start_date": "2025-07-15T11:49:43.154429",
1010
"achievements": []
11-
}
11+
}

0 commit comments

Comments
 (0)