def all_gt(nums, n):
i = []
for c in nums:
if c > n:
i += c
return i
This is the code that i used and ‘i’ is supposed to return the value in nums larger than n.
But mine returns nothing inside the bracket. E.g.,
all_gt([1,2,3,4], 2) => [3,4]
Anyone knows how to fix?
Thanks
You declared
ito be a list, so you need toappendto it instead of adding.Alternatively, you could have done this:
in place of the append.