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

From Script | Spoken-Tutorial
Jump to: navigation, search
Line 3: Line 3:
  
  
 
+
  {| Border =1
  {| style="border-spacing:0;"
+
  
 
  |'' Time''
 
  |'' Time''

Revision as of 10:59, 10 January 2013



> | 04.12
Time Narration


00.02 Hello Everybody. Welcome to the KTurtle tutorial



00.05 If this is the first time you are using KTurtle, please see the
“Introduction to KTurtle” tutorial on the spoken tutorial website.
00.12 To get started with KTurtle, I am using the Linux operating system ubuntu
Version 11.04 and KTurtle version 0.8.1 beta.


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


00.26 If you have already installed KTurtle,


00.28 go to the Ubuntu Menu Item Applications > Education and click

on the KTurtle Application.


00.34 Another way to open KTurtle is by going to Applications > Accessories
menu and click on Terminal


00.39 At the prompt type the name of the application that is “kturtle” and

hit 'Enter'.


00.46 This will open the application.


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


00.55 commands and comments


00.56 numbers, variables and strings


00.58 mathematical and comparison operators
01.00 and the boolean values


01.02 And the if and else conditions


01.05 The TurtleScript is a programming language and has different types

of words and symbols.


01.10 They are used for different purposes.


01.12 And it instructs KTurtle to do something.


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


01.24 Numbers can be stored in mathematical operators in comparison

operators.


01.28 They can also be stored in variables.


01.33 let us First have a look at variables, then we look at assigning values to
these variables.
01.38 In the editor of a Kturtle script ,let us open example for
avariable.


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


01.48 In the editor they are highlighted with the purple color.


01.52 Using the assignment, equal to a variable is given its content.


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


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


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


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


02.20 '$a = 2004 '$b = 25


02.27 Andprint $a + $b


02.33 First the value 2004 is assigned to the variable $a .
02.37 The next the value 2005,25'is assigned to variable '$b .



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



02.47 print takes numbers and strings as input.


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


02.57 I am now running the command , you can see that turtle has printed the
final result.
03.05 Let us next see the Mathematical and the Comparison Operators.


03.08 The basic mathematical operators here are +, - , * , /


03.16 In the editor of a Kturtle let us type the following example –


03.20 reset


03.23 canvassize 200,200which resizes the canvas to 200 pixels of width and
height each.


03.32 $add = 1 + 1


03.40 $subtract = 20 - 5


03.52 $multiply = 15 * 2


03.59 $divide = 30 /30


04.05 go 10,10


04.09 print $add
go 50,50


04.15 print $subtract


04.20 go 100,100


04.25 print $divide


04.30 go 0,0


04.34 Andprint $multiply


04.41 go 175,175


04.49 The canvas size 200,200 fix the width and height of the canvas to 200
pixels each.
04.55 The value 1+1 is assigned to the variable $+,
04.58 The 20-5 is assigned to variable subtract,
05.02 The value 15 * 2 will be assigned to the variable multiply.
05.06 30/30 is assigned to the variable Divide.


05.10 We will not print the variables ,the result which is assigned to them and
the turtle moves in the canvas.
05.16 Let us now run this code.The command which is getting executed is

highlighted in the editor and the turtle is printing the results.


05.34 You can see that the values have been printed on the canvas now.


05.39 Let us consider a simple example for using the comparison operator .Type the commands being shown on the screen


05.46 $answer = 10 > 3
05.51 Andprint $answer
06.02 Here 10 is compared with 3 the ’greater than’ operator.



06.08 The result of this comparison, the boolean value true will be stored in the
variable $answer, and the value true is printed.
06.15 Let me know Run this piece of code,you can see that the turtle has printed
the value true on the canvas.


06.24 lets see how Strings work in this application –


06.27 Strings can be put in variables, just like numbers.


06.31 Strings cannot be used in mathematical operators or comparison operators
and Strings are highlighted with red.
06.38 Strings start and end with the ''' mark, by these marks KTurtle knows
that it is a string.


06.45 For example:I am typing the print command followed by a string,See that
the string is highlighted in Red color.


06.56 When I run this piece of code, the turtle prints the chain on the canvas.
07.03 Boolean Values



07.04 There are only two boolean values: true and false.



07.07 For example –I am typing the example for using the boolean value in
kturtle.


07.14 $answer = 10 > 3


07.20 print $answer
07.25 The turtle choose the value true,the boolean value true is assigned the

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


07.36 Executing 'if' and 'else'conditions.


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


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


07.50 For example –


07.53 reset


07.55 $x = 4 I now have a sample piece of code on my editor here , which
compares the numbers 4 and 5 and prints the results accordingly.


08.03 Let me now run this code. The turtle has compared the variables 4 and 5 and
its printing the result 4 is smaller than 6 .


08.18 Now to the Assignment part.



08.20 Using the if and else conditions, the mathematical
operators, solve an equation and print the results using the print
and go command.
08.28 That is you can choose any four random numbers multiply the two sets of
random numbers, compare the results using the comparison operators and print
both the results and print that greater result at center of the canvas you

can choose any equation which you like.

08.45 I would like to acknowledge the spoken tutorial project
08.48 which is part of the talk to a teacher project.


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


08.56 you can see more information about this on the link shown on the screen.


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



-- Thanks and regards Madhuri Ganpathi

Contributors and Content Editors

Madhurig, Sneha