Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit5406047

Browse files
committed
Small tweaks, mostly to hints
1 parent4a1e414 commit5406047

File tree

2 files changed

+467
-24
lines changed

2 files changed

+467
-24
lines changed

‎backend/main/chapters/c06_lists.py‎

Lines changed: 33 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -822,7 +822,7 @@ class append_vs_concatenate(VerbatimStep):
822822
823823
- **`append`**: Add an element to the end of the list. `nums.append(4)` changes the list to `[1, 2, 3, 4]`.
824824
- **`len`**: Returns the number of elements. `len(nums)` is `3`.
825-
- **`range`**: `range(n)` is an object similar to the list of numbers from 0 to `n - 1`. In particular, `range(len(nums))` is like `[0, 1, 2]`.
825+
- **`range`**: `range(n)` is an object similar to the list of numbers from 0 to `n - 1`.That means it contains `n` numbers.In particular, `range(len(nums))` is like `[0, 1, 2]`, which are the indices of every element in `nums`.
826826
- **`subscripting`**: Get a value at an index. `nums[0]` is 1, `nums[1]` is 2, `nums[2]` is 3.
827827
- **`+`**: Concatenates lists. `nums + [4, 5]` is `[1, 2, 3, 4, 5]`.
828828
@@ -844,7 +844,7 @@ def program(self):
844844

845845
classpop_remove_index_subscript_assignment(VerbatimStep):
846846
"""
847-
As you see, `+` does not modify `nums`, but `append` does. (`new_nums` is not affected by the change in `nums`.)
847+
As youcansee, `+` does not modify `nums`, but `append` does.
848848
849849
Here's some new things. Try them out in the shell. Again suppose we have a list `nums = [1, 2, 3]`.
850850
@@ -900,6 +900,7 @@ def program(self):
900900
Removing the first element...
901901
and adding it to the end.
902902
Which functions/methods can you use for this?
903+
Remember that the first index is 0.
903904
"""
904905

905906
classsubscript_assignment_exercise(VerbatimStep):
@@ -926,8 +927,8 @@ def program(self):
926927
Your solution should have exactly three statements: `x = ['a', 'b', 'c']`, then one line copied exactly from the list (no additions), and `print(x)`.
927928
You need to get the value of the first element in `x`...
928929
and assign that value to the last position in `x`.
929-
Which function/method allowsyou to assign a value at a specific index in the list?
930-
How can you accessthe first and last elements in `x`?
930+
How doyou assign a value at a specific index in the list?
931+
What are the indices ofthe first and last last elements in `x`?
931932
"""
932933

933934
classnegative_index_concatenation_exercise(VerbatimStep):
@@ -966,9 +967,10 @@ def program(self):
966967

967968
hints="""
968969
Your solution should have exactly three statements: `x = ['a', 'b', 'c']`, `y = ` followed by one line copied exactly from the list, and `print(y)`.
969-
Which function/method allows you to create a new list?
970-
Start with the original list `x`.
971-
Then add something to it.
970+
Which lines of code create a new list rather than modifying?
971+
`x` is a list. Each element of `x` is a string.
972+
You can add lists together, you can add strings together, but you can't add a string and a list.
973+
How do you make a list containing one element?
972974
"""
973975

974976
classremove_exercise(VerbatimStep):
@@ -993,9 +995,11 @@ def program(self):
993995
hints="""
994996
Your solution should have exactly three statements: `x = [1, 2, 0, 3]`, one line copied exactly from the list (no additions), and `print(x)`.
995997
What does `x.remove(0)` do?
996-
Which function/method can do the same thing?
997-
Does that function/method need something else to work?
998-
Maybe another function/method?
998+
It removes an element!
999+
Which function/method can also remove an element?
1000+
The other function/method can't simply be told 'remove 0', it needs a different kind of information.
1001+
Specifically, it needs to be told where 0 is.
1002+
Which function/method provides that kind of information?
9991003
"""
10001004

10011005
final_text="""
@@ -1045,21 +1049,25 @@ class count_in_sorted_sum(VerbatimStep):
10451049
10461050
__copyable__
10471051
x = [1, 2, 0, 3]
1048-
print(1 in x)
1052+
y = 1 in x
1053+
print(y)
10491054
1050-
Replace the part `1 in x` with one line from the list above that does the same thing.
1055+
Replace the part `1 in x`(leave in the `y = `)with one line from the list above that does the same thing.
10511056
"""
10521057

10531058
program_in_text=False
10541059

10551060
defprogram(self):
10561061
x= [1,2,0,3]
1057-
print(x.count(1)>0)
1062+
y=x.count(1)>0
1063+
print(y)
10581064

10591065
hints="""
1060-
Your solution should have exactly two statements: `x = [1, 2, 0, 3]` and `print()` where one line is copied exactly from the list above and put inside the parentheses.
1061-
When is `1 in x` true?
1062-
What other function/method can tell us the same thing? And how?
1066+
Your solution should have exactly three statements: `x = ['a', 'b', 'c']`, `y = ` followed by one line copied exactly from the list, and `print(y)`.
1067+
When is `1 in x` True?
1068+
When `1` is in `x`!
1069+
Could be that `1` is in `x` once, or twice, or three times...
1070+
...but not zero times!
10631071
"""
10641072

10651073
classaverage_exercise(VerbatimStep):
@@ -1072,7 +1080,7 @@ class average_exercise(VerbatimStep):
10721080
print(y)
10731081
10741082
Replace the part after `y = ` with one line from the list above.
1075-
The final program should print the average of the numbers in `x`.
1083+
The final program should print the average(technically the *mean*)of the numbers in `x`.
10761084
"""
10771085

10781086
program_in_text=False
@@ -1084,9 +1092,10 @@ def program(self):
10841092

10851093
hints="""
10861094
Your solution should have exactly three statements: `x = [15, 12, -6, 3]`, `y = ` followed by one line copied exactly from the list, and `print(y)`.
1095+
If you're not sure, look up how to calculate the average/mean.
10871096
To calculate the average of numbers in `x` we need two things.
1088-
Which two functions/methodscan do those?
1089-
How do youuse those twotogether, to calculate the average?
1097+
Which two functions/methodsgive you those two things?
1098+
How do youcombine those twothings to calculate the average?
10901099
"""
10911100

10921101
classsum_range_exercise(VerbatimStep):
@@ -1099,7 +1108,7 @@ class sum_range_exercise(VerbatimStep):
10991108
print(y)
11001109
11011110
Replace the part after `y = ` with one line from the list above.
1102-
The final program should print thevalue of thesum: `1 + 2 + 3 + ... + x`.
1111+
The final program should print theresult ofadding up allthenumbers from `1` to `x` inclusive, i.e. `1 + 2 + 3 + ... + x`.
11031112
"""
11041113

11051114
program_in_text=False
@@ -1112,7 +1121,8 @@ def program(self):
11121121
hints="""
11131122
Your solution should have exactly three statements: `x = 100`, `y = ` followed by one line copied exactly from the list, and `print(y)`.
11141123
What function/method can be used to add up things?
1115-
Which function/method gives us something similar to the list of numbers `1, 2, 3, ..., x`?
1124+
Which function/method gives us the numbers `1, 2, 3, ..., x`?
1125+
You have to make a small tweak, otherwise that last number `x` will be left out.
11161126
"""
11171127

11181128
classsecond_smallest_in_list_exercise(VerbatimStep):
@@ -1138,6 +1148,8 @@ def program(self):
11381148
hints="""
11391149
Your solution should have exactly three statements: `x = [12, -6, 2, -1, 3]`, `y = ` followed by one line copied exactly from the list, and `print(y)`.
11401150
The numbers in `x` seem to be all out of order. Can you do something about that?
1151+
If you figured that part out, try using that function in the shell to play around with it.
1152+
How would you use that function to get the smallest value in a list? What about the biggest?
11411153
After that, how can you get the *second* smallest value?
11421154
"""
11431155

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp