Here are some extra puzzles created by students young and old. Some are very easy, some very hard. See if you can do them. Then, create your own puzzles to submit and we'll include them as well. Here's how ...
- Copy the
sample.py
or another than you like. - Change
load(whatever)
tocreate(uid,type,start_direction,startx,starty,title)
- Change
check()
towait()
until you perfect your puzzle - Change
wait()
tosave()
when you are ready to save it. Then run again. - Change the
create()
toload(uid)
- Change the
save()
tocheck()
- Test run it again with your solution
- Remove or change the lines of code you want players to fix or add
- Run one last time to test what your players will see
- Commit your changes to github and let us know about them to include
start_direction
, startx
, starty
and title
are optional. That's
it. Here's an example:
"""Draw a Square
Draw a square in three lines of code.
"""
import sys
sys.path.append('..')
import codestudio
artist = codestudio.create('square-loop','artist',90,0,0,'Draw a Square')
for count in range(4):
artist.move_forward(100)
artist.turn_right(90)
artist.save()
This will automatically save it into the puzzles
directory for you
and make sure there isn't one already saved there with your unique id.
The parameters to create()
are to help identify the puzzle solution and
setup the starting settings:
- A required string that will be the unique name and file name
- A required type of code.org puzzle ('artist', 'maze', or 'farmer')
- An optional starting direction to face (default 0, which is up)
- An optional starting x coordinate offset (default 0)
- An optional starting y coordinate offset (default 0)
- An optional title (default 'codestudio')
All you need to do after that is test your challenge by changing
create()
and save()
to load()
and check()
:
"""Draw a Square
Draw a square in three lines of code.
"""
import sys
sys.path.append('..')
import codestudio
artist = codestudio.load('square-loop')
for count in range(4):
artist.move_forward(100)
artist.turn_right(90)
artist.check()
Now just remove the code you want coders to figure out and replace with
some comments to give them hints, but they will already get the solution
drawn for them to see. Make sure your code contains nothing left off,
like loops without a body, because it will stop the solution from even
appearing. Use pass
if you need to for empty loops and such.
Place hint # ???
comments either on the line where they should begin
or on column 50 of the same line if that line needs to be changed.
"""Draw a Square
Draw a square in three lines of code.
"""
import sys
sys.path.append('..')
import codestudio
artist = codestudio.load('square-loop')
for count in range(4):
pass # ???
artist.check()
Keep in mind that if you want to change your saved puzzle later you will
have to edit the json
file directly in the puzzles
folder that you
saved for it or remove it and create the puzzle again. artist.save()
will
never overwrite an existing saved solution to keep you from breaking
others that are already working.
Don't forget to add the following two lines so that folks can just
solve these extras without moving anything or setting their
PYTHONPATH
, which they might not have learned how to do yet:
import sys
sys.path.append('..')
import codestudio
This also allows others to create their own collection of code puzzle challenges just by creating a directory structure or github repo like this:
./puzzles/sample.py
./sample.py
./README.md
People can see who contributed what by looking where they should, at the source files on GitHub. Adding these tags just makes more work to maintain them. Add a README.md file instead.
This is small, sure, but it allows your challenges to match those from
code.org and fit next to a coding window open on the right. It also allows
for future codestudio
Python development to add other widgets to the
main window.