Official Stanford Karel library used in CS 106A
This is a Python implementation of Karel for Stanford's CS 106A. This package is available on PyPI and allows you to run Karel programs without any additional setup!
Huge props to @nick-bowman for rewriting this project from scratch!
StanfordKarel now supports:
- Pip-installable package means you can run Karel programs from anywhere!
- Solution code no longer needed to grade assignments - instead, the output worlds are compared.
- Karel in ASCII! Plus autograder support.
- Improved autograding, testing, linting, and auto-formatting.
- Exception trace makes suggestions if you misspell a command (e.g.
pip install stanfordkarel
Follow the Karel tutorial on the Karel Reader!
First, ensure that StanfordKarel is correctly installed using pip.
.py file can become a Karel program!
from stanfordkarel import * def main(): """ Karel code goes here! """ turn_left() move() turn_left() if __name__ == "__main__": run_karel_program()
Save the file and run:
You can set a default world by passing a world name to run_karel_program,
Worlds should be saved/loaded in a
worlds/ folder in the same folder as the file being run.
worlds/(additional worlds go here)
If using the pip-installed version, create a Python file containing:
from stanfordkarel.world_editor import run_world_editor if __name__ == "__main__": run_world_editor()
./autograde runs the available tests using pytest in the
tests/ folder and prints out any output differences in the world.
The tests use the student's code and the expected world output to determine correctness. If the output is not the same, the test driver will print out an ASCII representation of the differences.
The autograde command also runs the builtin Karel Style Checker that performs linting automatically.
Everything important is located in
- Python 3.5+ is required because of
- Python 3.6+ is required for f-strings.
- Python 3.7+ is required for type annotations.
stanfordkarel/is the exported package, which contains all of the available functions and commands for students to use.
karel_application.pyis responsible for loading student code and displaying it to the screen.
All issues and pull requests are much appreciated!
- First, run
- To see test coverage scripts and other auto-formatting tools, use
- To run all tests, run
In the future, I hope to add:
- Automatic student style checking
- Ways of determining the student's strategy or approach from observing Karel movements
- Autograde more worlds, broken down by assignment
- Allow students to autograde their own work
- Accessibility for visually-impaired students
Release history Release notifications | RSS feed
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Hashes for stanfordkarel-0.2.6-py3-none-any.whl