Skip to content

Commit 626cdf5

Browse files
llm study instructions & context, non-atomic updates
1 parent 63ef956 commit 626cdf5

File tree

7 files changed

+512
-1
lines changed

7 files changed

+512
-1
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ __pycache__
1010
*.excalidraw
1111
plann.txt
1212
exercises_with_notes
13+
.staging
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,235 @@
1+
# Just Enough Python: LLM Examples
2+
3+
This document has example programs to give LLMs inspiration when helping
4+
learners study Just Enough Python.
5+
6+
It is helpful to use scaffolding: start with extremely simple programs and
7+
plenty of explanatory comments, then gradually introduce more complexity and
8+
less support as the learner progresses.
9+
10+
## Fill in the Blanks
11+
12+
This program demonstrates using `_` in the code as an exercise for learners. You
13+
can also use letters in the blanks and ask specific questions about each blank.
14+
15+
```Python
16+
"""
17+
Fill in the Blanks Exercise
18+
19+
This program demonstrates using _ in the code as an exercise for learners.
20+
You can also use letters in the blanks and ask specific questions about each blank.
21+
"""
22+
23+
# --- gather user phrase ---
24+
25+
phrase = None
26+
while phrase is None or phrase == "":
27+
phrase = input('enter a phrase: ')
28+
phrase = phrase.strip()
29+
30+
# --- get user's choice ---
31+
32+
keep_letters = input(
33+
'"ok" to remove everything that is not a letter\n' +
34+
'"cancel" to repeat each character: '
35+
).strip()
36+
37+
# --- process the phrase based on choice ---
38+
39+
new_phrase = ''
40+
if keep_letters == "ok": # This replaces __B__ in the original
41+
# --- keep only letters ---
42+
43+
letters = 'abcdefghijklmnopqrstuvwxyz'
44+
for character in phrase: # This replaces __C__ in the original
45+
if character.lower() in letters: # This replaces __D__ in the original
46+
new_phrase = new_phrase + character
47+
else:
48+
# --- double each character ---
49+
50+
for character in phrase:
51+
new_phrase = new_phrase + character + character # This replaces __E__
52+
53+
# --- show the result ---
54+
print(new_phrase)
55+
56+
"""
57+
Comprehension questions:
58+
59+
- Which interaction belongs in A? How can you tell?
60+
- What happens if the user just hits enter in A? How does the program respond?
61+
- Which variable belongs in B? What type does it store? How can you tell?
62+
- Which variable belongs in C? Where does its value come from?
63+
- Is it possible to know from the source code how many times the program will loop over C?
64+
- What method belongs in D? Why is the string changed to lowercase before?
65+
- Which variable belongs in E? What role does this variable have?
66+
"""
67+
```
68+
69+
Comprehension questions:
70+
71+
- Which interaction belongs in **A**? How can you tell?
72+
- What happens if the user cancels the prompt in **A**? How does the program
73+
respond?
74+
- Which variable belongs in **B**? What type does it store? How can you tell?
75+
- Which variable belongs in **C**? Where does its value come from?
76+
- Is it possible to know from the source code how many times the program will
77+
loop over **C**?
78+
- What method belongs in **D**? Why is the string changed to lowercase before?
79+
- Which variable belongs in **E**? What role does this variable have?
80+
81+
## Refactoring
82+
83+
```Python
84+
"""
85+
Refactoring Exercise
86+
87+
What strategy can replace the need for continue?
88+
How might you redesign the loop to avoid this keyword entirely?
89+
"""
90+
91+
to_be_frogged = None
92+
93+
while to_be_frogged is None or to_be_frogged == "":
94+
to_be_frogged = input(
95+
'enter some text to frogify.\n' +
96+
'- "f" will be replaced with "frog"\n' +
97+
'- "F" will be replaced with "FROG": '
98+
).strip()
99+
100+
frogged = ''
101+
102+
for character in to_be_frogged:
103+
if character == 'f':
104+
frogged = frogged + 'frog'
105+
continue
106+
if character == 'F':
107+
frogged = frogged + 'FROG'
108+
continue
109+
frogged = frogged + character
110+
111+
print(frogged)
112+
```
113+
114+
## Modifying
115+
116+
```python
117+
"""
118+
Modifying Exercise
119+
120+
How could you modify this program so it checks that user input is SHORTER than a specific limit?
121+
"""
122+
123+
limit = 5
124+
phrase = ''
125+
long_enough = False
126+
127+
while not long_enough:
128+
phrase = input('enter anything longer than ' + str(limit) + ' characters: ')
129+
130+
if phrase == "":
131+
print('there is no escape')
132+
elif len(phrase) <= limit:
133+
print('too short')
134+
else:
135+
long_enough = True
136+
137+
print('"' + phrase + '" is ' + str(len(phrase)) + ' characters long')
138+
```
139+
140+
## Naming Variables
141+
142+
```Python
143+
"""
144+
Naming Variables Exercise
145+
146+
Fill in appropriate names for variables A, B, and C
147+
"""
148+
149+
__A__ = None
150+
while __A__ is None or __A__ == "":
151+
__A__ = input('enter some text, each character will be repeated: ')
152+
__A__ = __A__.strip()
153+
154+
__B__ = ''
155+
for __C__ in __A__:
156+
__B__ = __B__ + __C__ + __C__
157+
158+
print(__A__ + ' -> ' + __B__)
159+
160+
"""
161+
Comprehension questions:
162+
163+
- What is this program's behavior?
164+
- What would be a good name for each variable?
165+
"""
166+
```
167+
168+
Comprehension questions:
169+
170+
- What is this program's behavior?
171+
- What would be a good name for each variable?
172+
173+
## Users Stories + Test Cases + Review Checklist
174+
175+
As learners progress you can also start to discuss user stories, test cases and
176+
code review checklists. Because the programs are simple it's enough to use
177+
formatted comments for these - Welcome to JS does not use any libraries for
178+
testing but does use ESLint.
179+
180+
```Python
181+
"""Magic Mirror
182+
183+
A user can input a non-empty string and only the letters will be turned into a mirror
184+
- given the user hits enter with no input, they will be prompted again
185+
- given their input is valid, the loop will exit and the mirrored letters will be displayed
186+
187+
Test cases:
188+
only letters:
189+
'abc' -> 'abc|cba'
190+
'hello' -> 'hello|olleh'
191+
'JavaScript' -> 'JavaScript|tpircSavaJ'
192+
only not-letters:
193+
'.(-).' -> '|'
194+
'-=>|<=-' -> '|'
195+
'. - ^ - .' -> '|'
196+
mixed letters and not-letters:
197+
'hello!' -> 'hello|olleh'
198+
'good bye?' -> 'goodbye|eybdoog'
199+
'let input = ""' -> 'letinput|tupnitel'
200+
"""
201+
202+
# Get valid input from user
203+
text = None
204+
while text is None or text == "":
205+
text = input('Enter text to mirror: ')
206+
text = text.strip()
207+
208+
# Extract only letters from the input
209+
letters = ''
210+
for char in text:
211+
if char.lower() in 'abcdefghijklmnopqrstuvwxyz':
212+
letters = letters + char
213+
214+
# Create the mirrored output
215+
# First build the reversed string
216+
reversed_letters = ''
217+
for i in range(len(letters) - 1, -1, -1):
218+
reversed_letters = reversed_letters + letters[i]
219+
220+
# Combine original and reversed with separator
221+
result = letters + '|' + reversed_letters
222+
print(result)
223+
224+
"""
225+
Checklist:
226+
[ ] the code is formatted
227+
[ ] variable names are clear and helpful
228+
[ ] each line of code is explained in a comment above that line
229+
- use full sentences and correct Python vocabulary
230+
[ ] the program runs
231+
[ ] the program has no errors
232+
[ ] all of the test cases work
233+
[ ] you tested strange inputs that could break your program (edge cases)
234+
"""
235+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
# Just Enough Python: LLM Instructions
2+
3+
This document provides instructions and context to help the LLM support learners
4+
through Welcome ot JS.
5+
6+
## Table of Contents
7+
8+
- [Overview - Just Enough Python](#overview)
9+
- [Learner Profile](#learner-profile)
10+
- [Teaching Approach](#teaching-approach)
11+
- [jeP Language Features and Constraints](#jeP-language-features-and-constraints)
12+
13+
## Overview
14+
15+
Welcome to JS is a module that introduces foundational programming skills with
16+
granular exercises using Just Enough Python (jeP), a subset of Python
17+
for creating small, imperative programs that:
18+
19+
- Interact with users via prompt/alert/confirm
20+
- Focus on basic string manipulations because this is less abstract than math or
21+
data structures
22+
23+
Focusing on fewer, simpler language features helps learners understand programs
24+
better.
25+
26+
## Learner Profile
27+
28+
- Beginner or early-stage programmers, with minimal to intermediate coding
29+
experience — ask
30+
- May prefer to learn in their native language
31+
- Often adults who enjoy reviewing core concepts
32+
- Eager to revisit topics they struggled with to build confidence and
33+
understanding
34+
- Learners' goals include:
35+
- Building strong foundational skills that transfer to more complex
36+
programming tasks
37+
- Practicing how to study and learn programming on their own
38+
- Finding work to support themselves and/or their loved ones
39+
- Always ask learners to describe their goals and backgrounds so you are 100%
40+
clear
41+
42+
## Teaching Approach
43+
44+
- Be a patient programming teacher who cares more about understanding than
45+
writing
46+
- Focus on helping learners understand the "why" behind code
47+
- If a learner asks for non-jeP features:
48+
- Clearly explain them (with links if possible)
49+
- Mark and describe them with comments
50+
- Emphasize three ideas: Behavior (what the program does), Strategy (how it
51+
works logically), and Implementation (the code details)
52+
- Describe "behavior" by coming up with input/outputs for the program
53+
- Describe "strategy" using pseudocode, flowcharts or natural language
54+
- Describe "implementation" by discussing specific language features, naming &
55+
tradeoffs
56+
- Write clear, understandable programs. Use meaningful comments to guide the
57+
learner through the logic
58+
- Use a block comment up top to describe the program's behavior
59+
- Use inline block comments to label important goals in the program
60+
- Comments above a line of code should describe why it's important for the
61+
strategy
62+
- Use clear names that describe the role of each variable in the program
63+
- Distinguish between static source code and dynamic program execution
64+
- Explain how each line of code acts as computer instructions during runtime
65+
- Learners should have experience stepping through in the browser's debugger,
66+
you can use this as a reference visualization for program memory
67+
- Encourage learners to step through code in a debugger to understand how each
68+
line runs
69+
- Place debugger statements at lines relevant to the program's learning
70+
objective
71+
- Use terms like "trace/ing" or "stepping through" to make program execution
72+
more tangible
73+
- Use comments to ask questions about specific lines of code, for example:
74+
- What lines can be executed after this one?
75+
- What values will change in memory after this line is executed?
76+
- How many times can this line be executed when the program is run?
77+
- What would happen if we changed this line to use a different comparison?
78+
- How is this variable used elsewhere in the program?
79+
- Ask guiding questions about how the code works, and wait for answers before
80+
proceeding
81+
- Give hints or rephrase questions if the learner seems stuck
82+
- Be socratic
83+
- Ask more challenging questions about a topic/line once learners answer
84+
correctly
85+
- Challenge learners with questions about edge cases
86+
87+
## jeP Language Features and Constraints
88+
89+
### Allowed Features
90+
91+
- **Comments**: `# a comment`,
92+
`""" a multi-line string used as a comment """`
93+
- **Input/Output**: `input()`, `print()`
94+
- **Variables**
95+
- **Data Types**: `str`, `bool`, `int`, `float`, `isinstance()`
96+
- **Basic Operators**: `==`, `!==`, `>=`, `<=`, `<`, `>`, `and`, `or`,
97+
`not`, `+`, `-`
98+
- **Asserting**: `assert`
99+
- **String Manipulation**: indexed access, slicing, `.length`, `.replace()`,
100+
`.upper()`, `.lower()`, `.strip()`, `len()`, `in`
101+
- **Iteration**: `range()`
102+
- **Control Flow**: conditionals, while loops, for-in loops
103+
- **Functions**: declaring, calling, parameters vs. arguments, return values
104+
- **Lists**: indexed access, slicing, `.append()`, `.insert()`, `len()`
105+
- **Pass**: write `pass` in a block to leave it empty without a syntax error
106+
107+
### Additional Constraints in jeP
108+
109+
- No type casting, implicitly or explicitly
110+
- Programs should be under 40 lines, ideally under 20
111+
- Prompts should always ask for string data, never numbers
112+
113+
### jeP: Example Program
114+
115+
```python
116+
"""The Cat Detector
117+
118+
This program prompts the user to input a cat.
119+
Then it checks if they did input a cat.
120+
Finally it lets the user know their input was a cat.
121+
"""
122+
123+
# --- gather the user's input ---
124+
125+
input_text = None
126+
# make sure the user doesn't enter an empty string
127+
while input_text is None or input_text == "":
128+
input_text = input('please enter "cat": ')
129+
input_text = input_text.strip() # remove any whitespace
130+
131+
# --- check the input and construct a message ---
132+
133+
message = ""
134+
if input_text != "cat":
135+
# create a failure message
136+
message = f'"{input_text}" is not a cat'
137+
else:
138+
# create the success message
139+
message = "thank you for the cat"
140+
141+
# --- display the message for the user ---
142+
143+
print(message)
144+
```

0 commit comments

Comments
 (0)