Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Karel (programming language)
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
== Specification == The following implementation is Karel in the [[Python (programming language)|Python programming language]].<ref>{{Cite web |last=Piech |first=Chris |last2=Roberts |first2=Eric |date=January 2019 |title=Karel the Robot Learns Python. Appendix: Reference |url=https://compedu.stanford.edu/karel-reader/docs/python/en/reference.html |access-date=2023-06-12 |website=compedu.stanford.edu}}</ref> Other implementations are available. === Primitive functions === The following are the primitive functions. <code>move()</code>: Karel moves one square in the direction it is facing. <code>turn_left()</code>: Karel turns left by 90 degrees. <code>put_beeper()</code>: Karel puts a beeper on its current square. <code>pick_beeper()</code>: Karel picks up a beeper from its current square. <code>paint_corner(COLOR_NAME)</code>: Karel paints its current corner with a color. There is a finite list of available colors. === Program Structures === Karel programs are structured in the following way: * Comments: Any line starting with <code>#</code> is a comment and is ignored by the interpreter. * Functions in Karel are declared using <code>def</code>, followed by the function name and parentheses. The body of the function follows in subsequent lines. * <code>main()</code>: A program run executes the <code>main</code> function. The other functions are not executed unless called. === Conditions in Karel === Karel can respond to certain conditions in its world: <code>front_is_clear(),</code><code>beepers_present(),</code> <code>beepers_in_bag(),</code> <code>left_is_clear(),</code> <code>right_is_clear(),</code> <code>facing_north(),</code> <code>facing_south()</code><code>,</code> <code>facing_east()</code><code>,</code> <code>facing_west()</code> And their inverses: <code>front_is_blocked(),</code> <code>no_beepers_present(),</code> <code>no_beepers_in_bag()</code><code>,</code> <code>left_is_blocked()</code><code>,</code> <code>right_is_blocked(),</code> <code>not_facing_north(),</code> <code>not_facing_south(),</code> <code>not_facing_east(),</code> <code>not_facing_west()</code><code>.</code> It can also check the current block's color by <code>corner_color_is(COLOR_NAME)</code>. === Conditions and Loops === There are two control structures: * Conditional execution using <code>if</code> and <code>else</code>. * Loops using <code>for</code> and <code>while</code>.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)