@@ -894,6 +894,14 @@ def program(self):
894894x .append (x .pop (0 ))
895895print (x )
896896
897+ hints = """
898+ Moving the first element to the end requires two things: removing the first element, and adding it to the end.
899+ Which function/method can remove and return the first element?
900+ Then which function/method can add that element to the end?
901+ You need to use `pop` and `append`.
902+ Make sure you choose the line that applies these two operations in the right order!
903+ """
904+
897905class subscript_assignment_exercise (VerbatimStep ):
898906"""
899907Good job. For the next exercise, start with the same incomplete program:
@@ -914,6 +922,15 @@ def program(self):
914922x [len (x )- 1 ]= x [0 ]
915923print (x )
916924
925+ 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.
932+ """
933+
917934class negative_index_concatenation_exercise (VerbatimStep ):
918935"""
919936Excellent!
@@ -948,6 +965,16 @@ def program(self):
948965y = x + [x [0 ]]
949966print (y )
950967
968+ hints = """
969+ 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?
976+ """
977+
951978class remove_exercise (VerbatimStep ):
952979"""
953980Great work. Now the final exercise:
@@ -967,6 +994,15 @@ def program(self):
967994x .pop (x .index (0 ))
968995print (x )
969996
997+ 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?
1004+ """
1005+
9701006final_text = """
9711007Great job!
9721008 """
@@ -988,9 +1024,9 @@ class count_in_sorted_sum(VerbatimStep):
9881024as you've now learned valuable fundamental skills. For example, you can use `in` to check if a list contains 5,
9891025but there's no similarly easy way to check for a number bigger than 5.
9901026
991- Now you will solve another set of four exercisesabout these newfunctions and methods, just like before .
992- Again, correct and incorrectsolutions are mixed together, and you must choose the correct line of code ,
993- replace the indicated part with it in your solution and run your code .
1027+ Now you will solve another set of four exercisesinvolving these newconcepts .
1028+ Again, correct and incorrectlines of code are mixed together,
1029+ and you must choose the correct line from the list .
9941030
9951031 sum(len(x))
9961032 sum(range(x))
@@ -1010,35 +1046,41 @@ class count_in_sorted_sum(VerbatimStep):
10101046 x.count(1) > 0
10111047 x.count(1) > 1
10121048
1013- First exercise:
1014-
1015- Write a program that takes a list `x` of numbers and prints `True` if `1 in x`, prints `False` otherwise.
1016- Here is the provided code for you to use. Replace the indicated part with a line from the list above, then run the code.
1049+ Here is a program:
10171050
10181051 __copyable__
10191052 x = [1, 2, 0, 3]
1020- y = (insert_one_line_from_above)
1021- print(y)
1053+ print(1 in x)
1054+
1055+ Replace the part `1 in x` with one line from the list above that does the same thing.
10221056 """
10231057
10241058program_in_text = False
10251059
10261060def program (self ):
10271061x = [1 ,2 ,0 ,3 ]
1028- y = x .count (1 )> 0
1029- print (y )
1062+ print (x .count (1 )> 0 )
1063+
1064+ 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.
1071+ """
10301072
10311073class average_exercise (VerbatimStep ):
10321074"""
1033- Excellent work! Next exercise:
1034-
1035- Write a program that takes a list `x` of numbers and prints the average of all the numbers in `x`.
1036- Here is the provided code for you to use. Replace the indicated part with a line from the list above, then run the code.
1075+ Excellent work! For the next exercise, start with this incomplete program:
10371076
10381077 __copyable__
10391078 x = [15, 12, -6, 3]
10401079 y = (insert_one_line_from_above)
10411080 print(y)
1081+
1082+ Replace the part after `y = ` with one line from the list above.
1083+ The final program should print the average of the numbers in `x`.
10421084 """
10431085
10441086program_in_text = False
@@ -1048,17 +1090,26 @@ def program(self):
10481090y = sum (x )/ len (x )
10491091print (y )
10501092
1093+ hints = """
1094+ 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.
1100+ """
1101+
10511102class sum_range_exercise (VerbatimStep ):
10521103"""
1053- Good job! Next exercise:
1054-
1055- Write a program that takes a positive number `x` and prints the value of the sum: `1 + 2 + 3 + ... + x`.
1056- Here is the provided code for you to use. Replace the indicated part with a line from the list above, then run the code.
1104+ Good job! For the next exercise, start with this incomplete program:
10571105
10581106 __copyable__
10591107 x = 100
10601108 y = (insert_one_line_from_above)
10611109 print(y)
1110+
1111+ Replace the part after `y = ` with one line from the list above.
1112+ The final program should print the value of the sum: `1 + 2 + 3 + ... + x`.
10621113 """
10631114
10641115program_in_text = False
@@ -1068,26 +1119,45 @@ def program(self):
10681119y = sum (range (x + 1 ))
10691120print (y )
10701121
1122+ 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]`?
1131+ """
1132+
10711133class second_smallest_in_list_exercise (VerbatimStep ):
10721134"""
10731135Excellent. And the last one:
10741136
1075- Write a program that takes a list of numbers `x` and prints the *second smallest value* in `x`.
1076- Here is the provided code for you to use. Replace the indicated part with a line from the list above, then run the code.
1077-
10781137 __copyable__
10791138 x = [12, -6, 2, -1, 3]
10801139 y = (insert_one_line_from_above)
10811140 print(y)
1141+
1142+ Replace the part after `y = ` with one line from the list above.
1143+ The final program should print the *second smallest value* in `x`.
10821144 """
10831145
10841146program_in_text = False
10851147
10861148def program (self ):
1087- x = [1 , 2 ,0 ,3 ]
1149+ x = [12 , - 6 , 2 ,- 1 ,3 ]
10881150y = sorted (x )[1 ]
10891151print (y )
10901152
1153+ 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.
1159+ """
1160+
10911161final_text = """
10921162Congratulations! You are now a master of list methods and functions!
10931163 """