16.6. Vary the Change Amount in RangeΒΆ
There is a version of range
that takes an change amount, so that you can go up by more than one each time, or even down by a negative number. Try it out!
Before you keep reading...
Runestone Academy can only continue if we get support from individuals like you. As a student you are well aware of the high cost of textbooks. Our mission is to provide great books to you for free, but we ask that you consider a $10 donation, more if you can or less if $10 is a burden.
- Start with numbers=[1,2,3,4,5,6,7,8,9,10]
- Yes, that would work, but there's an easier way
- Change the range to range(1,len(numbers),2)
- Yes, just by starting at 1, then skipping 2 each time, we'd collect the odds
- Change the range to range(0,len(numbers),1)
- No, that would collect all the numbers in evens
- Change the range to range(0,len(numbers),3)
- No, that would result in 0,3,6,9 in evens
Which of these changes to the program would give you just the odd values in a list? (Again: Try it!) Select all that work.
You have attempted 1 of 3 activities on this page