Skip to content

Commit a61935b

Browse files
committed
Annotate programs as copyable
1 parent c0549f0 commit a61935b

File tree

6 files changed

+30
-11
lines changed

6 files changed

+30
-11
lines changed

backend/main/chapters/c03_variables.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ class editor_hello_world(VerbatimStep):
185185
"""
186186
It's time to stop doing everything in the shell. In the top right you can see the *editor*. This is a place where you can write and run longer programs. The shell is great and you should keep using it to explore, but the editor is where real programs live.
187187
188-
Copy the program below into the editor, then click the 'Run' button:
188+
Type the program below into the editor, then click the 'Run' button:
189189
190190
__program_indented__
191191
"""

backend/main/chapters/c05_if_statements.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,8 @@ class print_tail(print_tail_base):
191191
"""
192192
Run this program:
193193
194-
__program_indented__
194+
__copyable__
195+
__program_indented__
195196
"""
196197

197198
class print_tail_snoop(print_tail_base):
@@ -348,6 +349,7 @@ class undefined_char(VerbatimStep):
348349
"""
349350
Here's a broken program:
350351
352+
__copyable__
351353
sentence = 'Hello World'
352354
excited = True
353355
@@ -526,7 +528,8 @@ class if_equals_replacing_characters(VerbatimStep):
526528
"""
527529
Let's use `==` in an `if` statement. In this program, the `if` body runs only when `c` is the character `'s'`. See for yourself.
528530
529-
__program_indented__
531+
__copyable__
532+
__program_indented__
530533
"""
531534

532535
def program(self):
@@ -593,7 +596,8 @@ class dna_example(VerbatimStep):
593596
594597
We're going to repeat that process. Let's try the same kind of program we just wrote:
595598
596-
__program_indented__
599+
__copyable__
600+
__program_indented__
597601
"""
598602

599603
def program(self):
@@ -782,7 +786,8 @@ class brokn_kyboard(VerbatimStep):
782786
"""
783787
Here's a cute little program using `!=`:
784788
785-
__program_indented__
789+
__copyable__
790+
__program_indented__
786791
"""
787792

788793
def program(self):

backend/main/chapters/c06_lists.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ class double_numbers(ExerciseStep):
178178
You can also create an empty list that has no elements.
179179
Check for yourself:
180180
181+
__copyable__
181182
numbers = [1, 2] + [3, 4]
182183
print(numbers)
183184
new_numbers = []
@@ -966,6 +967,7 @@ class run_with_python_tutor(VerbatimStep):
966967
There you can navigate through the program step by step with the "Prev" or "Next" buttons, or drag
967968
the slider left or right. You can also see the values of variables on the right.
968969
970+
__copyable__
969971
__program_indented__
970972
"""
971973

@@ -1000,7 +1002,8 @@ class two_separate_lists(VerbatimStep):
10001002
It's time to learn some technical details that are often misunderstood and lead to errors.
10011003
Run this program:
10021004
1003-
__program_indented__
1005+
__copyable__
1006+
__program_indented__
10041007
"""
10051008

10061009
def program(self):
@@ -1087,7 +1090,8 @@ class run_broken_with_python_tutor(VerbatimStep):
10871090
Consider this program. It loops through a list of numbers and removes the ones smaller than 10. Or at least, it tries to.
10881091
Run it with Python Tutor.
10891092
1090-
__program_indented__
1093+
__copyable__
1094+
__program_indented__
10911095
10921096
(remember that `numbers.pop(i)` removes the element from `numbers` at index `i`)
10931097
"""

backend/main/chapters/c07_nested_loops.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -689,7 +689,8 @@ class first_birdseye_example(VerbatimStep):
689689
690690
Here's an example program to run. Copy it into the editor and click the Bird's Eye button. This will open a new browser tab with the visualisation.
691691
692-
__program_indented__
692+
__copyable__
693+
__program_indented__
693694
"""
694695

695696
expected_code_source = "birdseye"
@@ -727,7 +728,8 @@ class birdseye_loop_example(VerbatimStep):
727728
728729
Here's a more complicated example to try out:
729730
730-
__program_indented__
731+
__copyable__
732+
__program_indented__
731733
"""
732734

733735
expected_code_source = "birdseye"

backend/main/chapters/c09_boolean operators.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ class InputAliceBob(VerbatimStep):
2121
The function below accepts one parameter, `name`, and checks if the person with the given name is among your friends.
2222
Copy and run the code in the editor:
2323
24-
__program_indented__
24+
__copyable__
25+
__program_indented__
2526
"""
2627
def program(self):
2728
def is_friend(name):
@@ -227,6 +228,7 @@ class AnExercise(ExerciseStep):
227228
It should return `True` if `x` is between 0 and 100 (inclusive), and return `False` otherwise.
228229
Your function should use `or`, and pass these tests:
229230
231+
__copyable__
230232
assert_equal(is_valid_percentage(-1), False)
231233
assert_equal(is_valid_percentage(0), True)
232234
assert_equal(is_valid_percentage(50), True)
@@ -312,6 +314,7 @@ class AndExercise(ExerciseStep):
312314
Let's practice now. Previously we wrote a function `is_valid_percentage` using `or`. Here's an example
313315
solution:
314316
317+
__copyable__
315318
def is_valid_percentage(x):
316319
if x < 0 or x > 100:
317320
return False
@@ -389,6 +392,7 @@ def is_valid_percentage(x):
389392
390393
Next exercise: given a list of three elements, check if all three elements are equal.
391394
395+
__copyable__
392396
def all_equal(row):
393397
...
394398
@@ -478,7 +482,8 @@ class valid_multiline(VerbatimStep):
478482
479483
Here are some examples. Pay close attention to the details.
480484
481-
__program_indented__
485+
__copyable__
486+
__program_indented__
482487
"""
483488

484489
def program(self):
@@ -553,6 +558,7 @@ class AndHasHigherPriority(ExerciseStep):
553558
Write a function to check if someone has won a game by placing 3 of the same pieces on one of the diagonal lines.
554559
The board is given as 3 lists of 3 strings each, and the function should return a boolean.
555560
561+
__copyable__
556562
def diagonal_winner(row1, row2, row3):
557563
...
558564
@@ -720,6 +726,7 @@ class NotPriority(ExerciseStep):
720726
Suppose that .png and .jpg files cannot be processed, but other file types can.
721727
Here's an example function to do that:
722728
729+
__copyable__
723730
def invalid_image(filename):
724731
if filename.endswith(".png") or filename.endswith(".jpg"):
725732
return False

backend/main/text.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ def __init__(cls, *args, **kwargs):
168168
cls.final_text = highlighted_markdown(cls.final_text.strip())
169169
cls.step_names.append("final_text")
170170
cls.step_texts.append(cls.final_text)
171+
assert "__copyable__" not in str(cls.step_texts)
171172

172173
@property
173174
def slug(cls):

0 commit comments

Comments
 (0)