bhylu.com

Advertisements

Code Challenge

Produce every multiple of three from three through twelve inclusively using range.

Understand the idea

Write your own solution before opening the worked answer. Predict the output from the supplied values, then compare the actual result. Check both an ordinary case and the boundary described below; a passing example is more useful when you can explain why it passes.

Where to try it

Open this example with Try in playground. The code loads as editable text and does not run until you select Run. The first run downloads Python. Each run starts fresh; temporary files created by a script are not files on your PC.

Your task

Produce every multiple of three from three through twelve inclusively using range.

Show the worked solution
Python

print(list(range(3, 13, 3)))

Check the result

The result is [3, 6, 9, 12].

Test one more case

Create the descending equivalent and verify that three is retained.