Difference between revisions of "KTurtle/C2/Grammar-of-TurtleScript-Part-I/English"

From Script | Spoken-Tutorial
Jump to: navigation, search
(Created page with '[http://spoken-tutorial.org/wiki/images/4/4b/Resources-Grammar_of_KTurtleScript_Part_I.zip Resources for "Grammar of TurtleScript Part I"] {| style="border-spacing:0;" | style="…')
 
 
(No difference)

Latest revision as of 14:30, 2 December 2012

Resources for "Grammar of TurtleScript Part I"

Visual Cue
Narration
Show Slide 1 Hello Everybody. Welcome to the KTurtle tutorial


If this is the first time you are using KTurtle, please see the “Introduction to KTurtle” tutorial on the spoken tutorial website.

Slide 2 To get started with KTurtle, I am using the Linux operating system Edubuntu Version 11.04 and KTurtle version 0.8.1 beta.


This tutorial will help you understand further, the Grammar of TurtleScript.

Switch to Terminal window If you have already installed KTurtle,


go to the Ubuntu Menu Item Applications > Education or Science

and click on the KTurtle Application.


Another way to open KTurtle in Ubuntu 11.04 is by going to Applications > Accessories > Terminal


and at the prompt type “kturtle” and hit 'Enter'.


This will open the application.

In this tutorial, we will learn, the grammar of turtle script which includes,


  • commands and comments
  • numbers, variables and strings
  • mathematical and comparison operators

and

  • the boolean values
  • the if and else conditions


The TurtleScript is a programming language and has different types of words and symbols.


They are used for different purposes.


And it is used to instruct KTurtle what to do.


The grammar of TurtleScript can include comments, commands, numbers, strings etc.

Numbers


Numbers can be used in mathematical operators and comparison operators.


They can also be stored in variables.



Switch to KTurtle window First we have a look at variables, then we look at assigning values to those variables.


Variables are words that start with a ‘$’, for example $a.


In the editor they are highlighted with purple.


Using the assignment, =, a variable is given its content.


Variables can contain any number, string or boolean (true/false) value.


It will keep that content until the program finishes executing or until the variable is reassigned to something else.


You can use variables, once assigned, just as if they are their content.


For example, consider the code being typed in the editor.

$a = 2004

$b = 25


print $a + $b


First the variable $a is assigned to the value 2004.


The next variable $b is assigned to the value 20.


The print command is used to command the turtle to write something on the canvas.


print takes numbers and strings as input.


print $a + $b add the two values and the turtle prints the value 2024.

Let us next see the Mathematical and Comparison Operators.


These are the basic mathematical operators +, - , * , /

Consider the following piece of code –


reset

canvassize 200,200

$add = 1 + 1

$subtract = 20 - 5

$multiply = 15 * 2

$divide = 30 /30

go 10,10

print $add

go 50,50

print $subtract

go 100,100

print $multiply

go 175,175

print $divide

go 0,0



The values resulting from the mathematical operations get assigned to various variables.



Let us consider the following simple comparison.


$answer = 10 > 3

print $answer


Here 10 is compared to 3 with the ’greater than’ operator.


The result of this comparison, the boolean value true is stored in the variable $answer, and the value true is printed.

Now lets see how Strings work in this application –


Strings can be put in variables, just like numbers.


Strings cannot be used in mathematical operators or comparison operators. Strings are highlighted with red.


Strings start and end with the ''' mark, by these marks KTurtle knows it is a string.

Boolean Values


There are only two boolean values: true and false.


For example –


$answer = 10 > 3

print $answer

go 0,0


the variable $answer is set to true because 10 is larger than 3.



Execute 'if' and 'else'


the code that is placed between the brackets will only be executed if the boolean value evaluates 'true'.


The code between the brackets after else is only executed if the if condition is false.


For example –


reset

$x = 4

if $x > 5 {

print " $x is greater than five !"

} else {

print " $x is smaller than six !"

}



Now to the Assignment part.


Using the if and else conditions, the mathematical operators, solve an equation and print the results using the print and go (to print the results on different places on the canvas) command.

I would like to acknowledge the spoken tutorial project


which is part of the talk to a teacher project.


It is supported by the National Mission on Education through ICT, MHRD government of India.


And you can see more information about this at this website.

Thank you this is Sindhu signing off. Enjoy exploring KTurtle.

Contributors and Content Editors

Chandrika, Pravin1389