
Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Great code hs karel cheat sheet
Typology: Cheat Sheet
1 / 1
This page cannot be seen from the preview
Don't miss anything!

On special offer
Overview of Programming Functionality
Programming Mode 1
● go… move one step forward. Note: If robot crashes into a wall, an error is thrown ● right… turn 90 degrees right ● left … turn 90 degrees left ● get … pick up a gem. Note: There must be a gem beneath the robot, or an error is thrown ● put… drops a gem on the ground. Note: Error is thrown if robot’s bag is empty ● repeat … repeat a command or sequence of commands a given number of times
Programming Mode 2
● if else… conditions ● sensors ... wall, gem, north, empty, home ● not … negation ● while… do something while condition is satisfied ● def … define custom commands
Programming Mode 3
● print … print command same as in Python ○ for example print “Hello World!”, or print “a =”, a ● gpsx, gpsy … GPS coordinates, can be assigned to a variable ● integer and logical variables … for example, a = 0creates a new variable a and initializes it with zero ● inc(a), inc(a, value)… increase the value of variable aby one or value ● dec(a), dec(a, value)… decrease the value of variable aby one or value ● rand… returns randomly True or False ● return… can be used in custom commands to return value ● and, or… logical and, or to be used in conditions, while loops, and logical variables ● lists … functionality related to lists is the same as in Python ○ L = [] creates an empty list L ○ len(L)… length of list L ○ L[i]… item in list Lat position i. Note: Indexing starts from zero ○ L.append(x)… append item xat the end of list L ○ x = L.pop() … remove the last item in list Land return it ○ del L[i] … delete item at position i in list L