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

Commit4a1e414

Browse files
committed
simplified hints
1 parente9cf80b commit4a1e414

File tree

1 file changed

+30
-47
lines changed

1 file changed

+30
-47
lines changed

‎backend/main/chapters/c06_lists.py‎

Lines changed: 30 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -895,11 +895,11 @@ def program(self):
895895
print(x)
896896

897897
hints="""
898-
Moving the first element to the end requires two things: removingthefirst element, andadding it to the end.
899-
Which function/method can remove and returnthefirst element?
900-
Then which function/method can add thatelement to the end?
901-
You needtouse `pop` and `append`.
902-
Make sureyouchoose the line that applies these two operations in the right order!
898+
Your solution should have exactly three statements: `x = ['a', 'b', 'c']`, then one line copied exactly fromthelist (no additions), and`print(x)`.
899+
Moving the first element totheend requires two things.
900+
Removing the firstelement...
901+
and adding ittothe end.
902+
Which functions/methods canyouuse for this?
903903
"""
904904

905905
classsubscript_assignment_exercise(VerbatimStep):
@@ -923,12 +923,11 @@ def program(self):
923923
print(x)
924924

925925
hints="""
926-
Which function/method allows you to assign a value to a specific position in the list?
927-
You need to use subscript assignment.
928-
How do you assign a value to the last position in `x`?
929-
You need to use `len(x)` to access the last element.
930-
Which line in the list above involving `len(x)` accesses the last position correctly?
931-
Remember the list index starts counting from 0.
926+
Your solution should have exactly three statements: `x = ['a', 'b', 'c']`, then one line copied exactly from the list (no additions), and `print(x)`.
927+
You need to get the value of the first element in `x`...
928+
and assign that value to the last position in `x`.
929+
Which function/method allows you to assign a value at a specific index in the list?
930+
How can you access the first and last elements in `x`?
932931
"""
933932

934933
classnegative_index_concatenation_exercise(VerbatimStep):
@@ -966,13 +965,10 @@ def program(self):
966965
print(y)
967966

968967
hints="""
968+
Your solution should have exactly three statements: `x = ['a', 'b', 'c']`, `y = ` followed by one line copied exactly from the list, and `print(y)`.
969969
Which function/method allows you to create a new list?
970-
You may be tempted to use `append` but that modifies the original list `x`.
971-
You need to use `+`. Remember this requires two lists.
972-
Start with the original list `x`. Then add another list to it.
973-
How do you get the first element of `x`? And then turn it into a second list?
974-
`x.pop(0)` will give us the first element, but it modifies the original list, which we need unchanged.
975-
Which line from the list above correctly turns the first element into a second list?
970+
Start with the original list `x`.
971+
Then add something to it.
976972
"""
977973

978974
classremove_exercise(VerbatimStep):
@@ -995,12 +991,11 @@ def program(self):
995991
print(x)
996992

997993
hints="""
998-
`x.remove(0)` finds the first occurrence of `0` in `x` and removes it.
999-
What other function/method can remove an element from a list?
1000-
`pop` can remove an element, but it requires an index.
1001-
Is there a function/method that can find the index of the first occurrence of an element?
1002-
`index` can do that.
1003-
Which line from the list above applies these two operations in the correct order?
994+
Your solution should have exactly three statements: `x = [1, 2, 0, 3]`, one line copied exactly from the list (no additions), and `print(x)`.
995+
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?
1004999
"""
10051000

10061001
final_text="""
@@ -1062,12 +1057,9 @@ def program(self):
10621057
print(x.count(1)>0)
10631058

10641059
hints="""
1065-
`1 in x` is `True` if `x` contains the number `1`, `False` otherwise.
1066-
What other function/method can tell us if `x` contains `1`?
1067-
`count` can do that.
1068-
Which line from the list above involving `count` correctly detects `1 in x`?
1069-
If `x` contains `1`, then the count of `1` should be at least one.
1070-
That is, it must be greater than zero.
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?
10711063
"""
10721064

10731065
classaverage_exercise(VerbatimStep):
@@ -1091,12 +1083,10 @@ def program(self):
10911083
print(y)
10921084

10931085
hints="""
1086+
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)`.
10941087
To calculate the average of numbers in `x` we need two things.
1095-
We need to add up all the numbers in `x`, and we need how many numbers in `x` there are.
1096-
Which two functions/methods can do that?
1097-
`sum` and `len`.
1098-
Which line from the list above correctly calculates the average?
1099-
The average is calculated by dividing the total sum by the number of elements.
1088+
Which two functions/methods can do those?
1089+
How do you use those two together, to calculate the average?
11001090
"""
11011091

11021092
classsum_range_exercise(VerbatimStep):
@@ -1120,14 +1110,9 @@ def program(self):
11201110
print(y)
11211111

11221112
hints="""
1123-
One function/method we need to use is already mentioned in the exercise.
1124-
It's `sum`. Which other function/method do we need?
1125-
How can we `sum` the numbers `1, 2, 3, ..., x`? If only we had a list of these numbers.
1126-
Since we are adding them up, a list of the numbers `0, 1, 2, 3, ..., x` would also work.
1127-
Which function/method gives us something similar to the list of numbers `0, 1, 2, 3, ..., x`?
1128-
Remember that `range(x)` is similar to `[0, 1, 2, ..., x - 1]`.
1129-
That's very close to what we need, but not quite.
1130-
Which line from the list above correctly uses `range` to give us `[0, 1, 2, ..., x]`?
1113+
Your solution should have exactly three statements: `x = 100`, `y = ` followed by one line copied exactly from the list, and `print(y)`.
1114+
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`?
11311116
"""
11321117

11331118
classsecond_smallest_in_list_exercise(VerbatimStep):
@@ -1151,11 +1136,9 @@ def program(self):
11511136
print(y)
11521137

11531138
hints="""
1154-
To find the second smallest value in `x` we can order the numbers in `x` from smallest to largest.
1155-
Which function/method can order the numbers in `x` like that?
1156-
It's `sorted`.
1157-
Then how do we access the *second* element in `sorted(x)`?
1158-
Remember the list index starts counting from 0.
1139+
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)`.
1140+
The numbers in `x` seem to be all out of order. Can you do something about that?
1141+
After that, how can you get the *second* smallest value?
11591142
"""
11601143

11611144
final_text="""

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp