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!
- 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
csp-16-6-2: Which of these changes to the program would give you just the odd values in a list? (Again: Try it!) Select all that work.
Before you keep reading...
Making great stuff takes time and $$. If you appreciate the book you are reading now and want to keep quality materials free for other students please consider a donation to Runestone Academy. We ask that you consider a $10 donation, but if you can give more thats great, if $10 is too much for your budget we would be happy with whatever you can afford as a show of support.
You have attempted 1 of 3 activities on this page