1 00:00:01 --> 00:00:01 Hello everybody. 2 00:00:02 --> 00:00:07 Welcome to this tutorial on Grammar of TurtleScript in KTurtle. 3 00:00:08 --> 00:00:10 In this tutorial, we will learn about 4 00:00:11 --> 00:00:15 Grammar of Turtle script and 'if'-'else' condition 5 00:00:16 --> 00:00:28 To record this tutorial I am using, Ubuntu Linux OS version. 12.04. KTurtle version. 0.8.1 beta. 6 00:00:29 --> 00:00:34 We assume that you have basic working knowledge of KTurtle 7 00:00:35 --> 00:00:39 If not, for relevant tutorials, please visit our website. http://spoken-tutorial.org 8 00:00:40 --> 00:00:42 Let's open a new KTurtle Application. 9 00:00:43 --> 00:00:44 Click on Dash home. 10 00:00:45 --> 00:00:48 In the Search bar, type KTurtle. 11 00:00:49 --> 00:00:51 Click on the KTurtle icon. 12 00:00:52 --> 00:00:55 We can also open KTurtle using Terminal. 13 00:00:56 --> 00:01:00 Press CTRL+ALT+T simultaneously to open the Terminal. 14 00:01:01 --> 00:01:07 Type KTurtle and press enter to open the KTurtle Application. 15 00:01:08 --> 00:01:10 Let's first look at TurtleScript 16 00:01:11 --> 00:01:14 TurtleScript is a programming language 17 00:01:15 --> 00:01:20 It has different types of words and symbols used for various purposes 18 00:01:21 --> 00:01:24 It instructs Turtle what to do 19 00:01:25 --> 00:01:29 Grammar of TurtleScript in KTurtle includes- 20 00:01:30 --> 00:01:30 Comments 21 00:01:31 --> 00:01:31 Commands 22 00:01:32 --> 00:01:32 Numbers 23 00:01:33 --> 00:01:33 Strings 24 00:01:34 --> 00:01:35 Variables and 25 00:01:36 --> 00:01:37 Boolean values 26 00:01:38 --> 00:01:41 Now we will see where to store numbers 27 00:01:42 --> 00:01:43 Numbers can be stored in 28 00:01:44 --> 00:01:45 Mathematical operators 29 00:01:46 --> 00:01:48 Comparison operators and 30 00:01:49 --> 00:01:49 Variables 31 00:01:50 --> 00:01:53 I will zoom the program text for clear view. 32 00:01:54 --> 00:01:56 First let's look at variables. 33 00:01:57 --> 00:02:03 Variables are words that start with ‘$’ sign, for example $a. 34 00:02:04 --> 00:02:08 Variables are highlighted in purple color. 35 00:02:09 --> 00:02:13 Using the assignment, equal to (=), a variable is given its content. 36 00:02:14 --> 00:02:19 Variables can contain numbers $a=100. 37 00:02:20 --> 00:02:24 strings $a=hello or 38 00:02:25 --> 00:02:31 boolean values that is true or false $a=true 39 00:02:32 --> 00:02:40 Variable keeps the content until program finishes execution or until it is reassigned to something else. 40 00:02:41 --> 00:02:43 For example, consider the code. 41 00:02:44 --> 00:02:49 Let us type,$a = 2004 42 00:02:50 --> 00:02:54 $b = 25 43 00:02:55 --> 00:03:00 print $a + $b 44 00:03:01 --> 00:03:05 Variable 'a' is assigned a value 2004. 45 00:03:06 --> 00:03:09 Variable 'b' is assigned a value 25 46 00:03:10 --> 00:03:14 print command, commands Turtle to write something on the canvas. 47 00:03:15 --> 00:03:18 print command, takes numbers and strings as input. 48 00:03:19 --> 00:03:28 print $a + $b commands Turtle to add two values and display them on the canvas. 49 00:03:29 --> 00:03:33 Let's Run the code in slow speed. 50 00:03:34 --> 00:03:39 Value 2029 is displayed on the canvas 51 00:03:40 --> 00:03:43 Let us next see the Mathematical Operators. 52 00:03:44 --> 00:03:52 Mathematical operators include, + (Addition) - (Subtraction) * (Multiplcation) and / (Division) 53 00:03:53 --> 00:04:00 I will clear the current code from editor and type clear command and RUN to clean the canvas 54 00:04:01 --> 00:04:04 I already have a program in a text editor. 55 00:04:05 --> 00:04:07 I will Explain the code now 56 00:04:08 --> 00:04:11 “reset” command sets Turtle to its default position 57 00:04:12 --> 00:04:21 canvassize 200,200 fixes the width and height of the canvas to 200 pixels each. 58 00:04:22 --> 00:04:25 value 1+1 is assigned to the variable $add, 59 00:04:26 --> 00:04:30 Value 20-5 is assigned to variable $subtract, 60 00:04:31 --> 00:04:35 value 15 * 2 is be assigned to the variable $multiply. 61 00:04:36 --> 00:04:39 30/30 is assigned to the variable $divide. 62 00:04:40 --> 00:04:51 go 10,10 commands to Turtle to go 10 pixels left of canvas and 10 pixels from top of canvas 63 00:04:52 --> 00:04:55 print command displays the varible on the canvas 64 00:04:56 --> 00:05:02 I will copy the code from text editor and paste it into KTurtle editor. 65 00:05:03 --> 00:05:07 Pause the tutorial and type the program into KTurtle editor. 66 00:05:08 --> 00:05:12 Resume the tutorial after typing the program 67 00:05:13 --> 00:05:16 Let us click on Run button to run the program 68 00:05:17 --> 00:05:21 Command which is getting executed is highlighted on the editor. 69 00:05:22 --> 00:05:33 Turtle displays the values on the canvas at the specified positions. 70 00:05:34 --> 00:05:40 Let us consider a simple example for using comparison operator . 71 00:05:41 --> 00:05:48 I will clear the current code from editor and type clear command and RUN to clean the canvas 72 00:05:49 --> 00:05:52 I will zoom the progrm text to have clear view 73 00:05:53 --> 00:05:54 Let's type 74 00:05:55 --> 00:06:02 $answer = 10 > 3 75 00:06:03 --> 00:06:08 print $answer 76 00:06:09 --> 00:06:13 Here 10 is compared to 3 with the ’greater than’ operator. 77 00:06:14 --> 00:06:18 The result of this comparison, the boolean value true is stored in the 78 00:06:19 --> 00:06:26 variable $answer and the value true is displayed on the canvas. 79 00:06:27 --> 00:06:28 Let's run the code now 80 00:06:29 --> 00:06:33 Turtle displays Boolean value true on the canvas. 81 00:06:34 --> 00:06:38 Now lets see how Strings work in this application – 82 00:06:39 --> 00:06:42 Strings can be put in variables like numbers 83 00:06:43 --> 00:06:48 Strings cannot be used in mathematical or comparison operators 84 00:06:49 --> 00:06:52 Strings are highlighted in red color 85 00:06:53 --> 00:06:59 KTurtle identifies a line in double quotes as a string 86 00:07:00 --> 00:07:07 I will clear the current code from editor.type clear command and Run to clean the canvas 87 00:07:08 --> 00:07:10 Now I will explain about Boolean values. 88 00:07:11 --> 00:07:15 There are only two boolean values: true and false. 89 00:07:16 --> 00:07:19 For example Let's type the code 90 00:07:20 --> 00:07:27 $answer = 7<5 91 00:07:28 --> 00:07:33 print $answer 92 00:07:34 --> 00:07:42 Boolean value false is assigned to variable $answer because 7 is greater than 5 93 00:07:43 --> 00:07:46 Let's Run the code now 94 00:07:47 --> 00:07:50 Turtle diplays Boolean value false on the canvas. 95 00:07:51 --> 00:07:55 Let's next learn about “if-else” conditon. 96 00:07:56 --> 00:08:02 ‘if’ condition is executed only if the boolean value evaluates ‘true’ 97 00:08:03 --> 00:08:08 ‘else’ condition is executed only if the ‘if’ condition is ‘false’ . 98 00:08:09 --> 00:08:16 I will clear the current code from editor.type clear command and Run to clean the canvas 99 00:08:17 --> 00:08:20 I already have a code in a text file. 100 00:08:21 --> 00:08:29 This code compares numbers 4 , 5 and 6 and displays the results accordingly on the canvas. 101 00:08:30 --> 00:08:35 I will copy the code from text editor and paste it into KTurtle editor. 102 00:08:36 --> 00:08:41 Pause the tutorial and type the program into your KTurtle editor. 103 00:08:42 --> 00:08:45 Resume the tutorial after typing the program 104 00:08:46 --> 00:08:48 Let's Run the code now 105 00:08:49 --> 00:08:52 the Turtle has compared the values 4 and 5. 106 00:08:53 --> 00:08:59 and has displayed the result 4 is smaller than 6 on the canvas . 107 00:09:00 --> 00:09:04 With this we come to the end of this tutorial. 108 00:09:05 --> 00:09:06 Let's summarize. 109 00:09:07 --> 00:09:10 In this tutorial, we have learnt about 110 00:09:11 --> 00:09:13 Grammar of Turtle script and 111 00:09:14 --> 00:09:16 ‘if-else’ condition 112 00:09:17 --> 00:09:18 Now to the assignment part. 113 00:09:19 --> 00:09:21 Solve an equation using 114 00:09:22 --> 00:09:23 if - else condition 115 00:09:24 --> 00:09:26 Mathematical and comparision operators 116 00:09:27 --> 00:09:32 Display the results using “print” and “go” commands. 117 00:09:33 --> 00:09:34 To solve the assignment 118 00:09:35 --> 00:09:37 Choose any four random numbers 119 00:09:38 --> 00:09:41 Multiply two sets of random numbers 120 00:09:42 --> 00:09:45 Compare the results using the comparison operators 121 00:09:46 --> 00:09:48 Display both the results 122 00:09:49 --> 00:09:53 Display greater result at the center of the canvas 123 00:09:54 --> 00:09:58 You can choose any equation which you like. 124 00:09:59 --> 00:10:02 Watch the video available at this URL http://spoken-tutorial.org/What is a Spoken Tutorial 125 00:10:03 --> 00:10:05 It summarises the Spoken Tutorial project 126 00:10:06 --> 00:10:11 If you do not have good bandwidth, you can download and watch it 127 00:10:12 --> 00:10:13 The Spoken Tutorial Project Team : 128 00:10:14 --> 00:10:17 Conducts workshops using spoken tutorials 129 00:10:18 --> 00:10:21 Gives certificates to those who pass an online test 130 00:10:22 --> 00:10:29 For more details, please write to contact@spoken-tutorial.org 131 00:10:30 --> 00:10:34 Spoken Tutorial Project is a part of the Talk to a Teacher project 132 00:10:35 --> 00:10:42 It is supported by the National Mission on Education through ICT, MHRD, Government of India 133 00:10:43 --> 00:10:47 More information on this Mission is available at this link http://spoken-tutorial.org/NMEICT-Intro ] 134 00:10:48 --> 00:10:51 The Script is contributed by ITfC Bangaluru. 135 00:10:52 --> 00:10:57 This is Madhuri Ganpathi from IIT Bombay signing off Thank you for joining.