You signed in with another tab or window.Reload to refresh your session.You signed out in another tab or window.Reload to refresh your session.You switched accounts on another tab or window.Reload to refresh your session.Dismiss alert
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
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?
970
+
Start with the original list `x`.
971
+
Then add something to it.
976
972
"""
977
973
978
974
classremove_exercise(VerbatimStep):
@@ -995,12 +991,11 @@ def program(self):
995
991
print(x)
996
992
997
993
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?
1004
999
"""
1005
1000
1006
1001
final_text="""
@@ -1062,12 +1057,9 @@ def program(self):
1062
1057
print(x.count(1)>0)
1063
1058
1064
1059
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?
1071
1063
"""
1072
1064
1073
1065
classaverage_exercise(VerbatimStep):
@@ -1091,12 +1083,10 @@ def program(self):
1091
1083
print(y)
1092
1084
1093
1085
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)`.
1094
1087
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?
1100
1090
"""
1101
1091
1102
1092
classsum_range_exercise(VerbatimStep):
@@ -1120,14 +1110,9 @@ def program(self):
1120
1110
print(y)
1121
1111
1122
1112
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`?
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?