Try it on paper first. A hint, the key idea and the worked solution are here when you need them.
Write a recursive function all_positive(items) that gives True if every item of the list is more than 0, and False if any item is 0 or less. What is the answer for an empty list?
Have you tried it?
Work it out on paper first. It is fine to get stuck or make a mistake: that is how we learn. When you are ready, go through the solution one step at a time, and check each step against your own.
Plan. Use the first item and the rest.
True. (This is the usual agreement: "every item passes" is true when there are no items.)False at once. Otherwise, the answer is the answer for the rest.Check. The first list is all positive: True. The second has a 0: False, found at the second item, and the third item is never looked at. The empty list gives True.
Answer: True, False and True.
Log in to join the discussion.
Loading…
With Standard, you also open 10 more problems, 2 Python labs and 1 extra course. Everything you have used here stays free, always.