KTurtle/C3/Question-Glues/English
Title of the tutorial: Question-Glues
Author: Madhuri Ganapathi
Key words: Question glues, 'and', 'not', 'or', if-else, message, Video tutorial
Visual Cue | Narration |
---|---|
Slide Number 1 | Hello and
Welcome to the spoken tutorial on Question Glues in KTurtle. |
Slide Number 2
Learning Objectives |
In this tutorial, we will learn the following question glues
|
Slide Number 3
System Requirement |
To record this tutorial I am using,
Ubuntu Linux OS Version 12.04. KTurtle version 0.8.1 beta. |
Slide Number 4
Pre-requisites |
We assume that you have basic working knowledge of KTurtle and
“if-else” statement in KTurtle If not, for relevant tutorials, please visit our website. |
Before proceeding, let me explain about question glue words. | |
Slide Number 5
Question Glues |
Question glue words enable us to glue small questions into one big question.
“and”, “or” and “not” are some glue-words. Glue-words are used together with if-else conditions. |
Switch to KTurtle Application
Dash home >>Search bar appears>> In the Search bar type KTurtle |
Let's open a new KTurtle Application.
Click on Dash home. In the Search bar, type KTurtle. Click on the option. |
Let's begin the tutorial with the glue word and. | |
I already have a program in a text editor. | |
#program to check triangle is scalene or not
reset message"Triangle's Inequality: In a triangle, sum of the lengths of any two sides is greater than the third side " $a =ask"enter length of side AB and click OK" $b =ask"enter length of side BC and click OK" $c=ask"enter length of side AC and click OK" #if condition below checks if sum of lengths of any two sides is greater than third side if(($a+$b>$c) and ($b+$c>$a) and ($c+$a>$b)){ #if condition below checks sides of triangle are not equal if(($a !=$b) and ($b != $c) and ($c != $a)) { fontsize 18 go 10,100 print "A scalene triangle" } else { go 10,100 print" Not a scalene triangle" } } else{ go 10,100 print"Does not satisfy triangle's inequality " } |
Let me copy the code from the text editor and paste it into KTurtle editor.
Please pause the tutorial here and type the program into your KTurtle editor.
|
Zoom text | Let me zoom into the program text.
It may possibly be a little blurred. |
Let's look the code. | |
Highlight reset | reset command sets Turtle to its default position. |
Highlight message"In a triangle
sum of the lengths any two sides is greater than third side " |
Message in a program is given within double quotes after the keyword message " " .
“message” command takes “string” as input. It shows a pop-up dialog box containing text from the string and also generates a beep for non null strings. |
Highlight $a, $b and $c | $a, $b and $c are variables that store user input. |
Highlight ask" " | “ask” command prompts for user input to be stored in variables. |
Highlight if(($a+$b>$c) and ($b+$c>$a) and ($c+$a>$b) | if(($a+$b>$c) and ($b+$c>$a) and ($c+$a>$b),
checks the “if” condition. When the two questions glued with “and” are true, result is true. |
Highlight if(($a !=$b) and ($b != $c) and ($c != $a)) { | if(($a !=$b) and ($b != $c) and ($c != $a)){
checks the "if" condition when 'if' condition above is true, control moves into nested if block. It checks whether sides of triangle are unequal. |
Highlight fontsize 18 | fontsize 18 sets the font size used by print command. |
Highlight go 10,100 | go 10,100 commands Turtle to go 10 pixels from left of canvas and 100 pixels from top of canvas. |
Highlight print "A scalene triangle" | print command displays the string after checking the if condition. |
else { | else command checks else condition, when if condition in the block is false |
Highlight print" Not a scalene triangle" | print command displays the string after checking the else condition. |
Highlight else | else command checks the final condition.
else is checked only when above conditions are false. |
Highlight print"Does not satisfy triangle's inequality " | print command displays the string after checking the else condition. |
I will the code to check all the conditions. | |
Run the program | Let's click on the Run button to run the code. |
Point to the dialog box. | A message dialog box pops up.
Let me click OK. |
Point to the result | Let's enter 5 for 'length of AB' and click OK
8 for 'length of BC' and click OK 9 for 'length of AC' and click OK “A scalene triangle” is displayed on the canvas. |
Run the program | Let's run again |
Point to the dialog box. | A message dialog box pops up again.
Let me click OK. |
Point to the result | Let's enter 5 for length of'AB' and click OK
6 for length of 'BC' and click OK 6 for length of 'AC' and click OK “Not a scalene triangle” is displayed on the canvas. |
Run the program | Let's run again to check default condition. |
Point to the result | Meesgae dialog box pops up. Let me click Ok
Let's enter 1 for length of 'AB' and click OK 1 for length of 'BC' and click OK 2 for length of 'AC' and click OK " Does not satisfy triangle's inequality " is displayed on canvas. |
Let's now clear the program. Let me type clear command and run clear command, cleans the canvas | |
Next let's work with not condition. | |
#program checks triangle is equilateral or not
reset $a=ask"enter length of AB and click OK" $b=ask"enter length of BC and click OK" $c=ask"enter length of AC and click OK" if not(($a==$b)and($b==$c)and($c==$a)){ print "Triangle is not equilateral" } else { print "Triangle is equilateral" go 100,100 repeat 3{turnright 120 forward 100}} |
Let me copy the program from the text editor and paste it into the KTurtle editor.
Resume the tutorial after typing the program. |
Zoom text | Let me zoom into the program text and explain the program |
Highlight reset | reset command sets Turtle todefault position. |
Highlight $a, $b and $c | $a, $b and $c are variables that store user input. |
Highlight if not (($a==$b) and ($b==$c) and ($c==$a)){ | if not (($a==$b) and ($b==$c) and ($c==$a)){
checks the if not condition not is a special question glue-word. It inverses the logical state of its operand. e.g. If the given condition is true, not makes it false. And when the condition is false the output will be true. |
Highlight print "Triangle is not equilateral" | print command displays the string after checking the if not condition. |
Highlight else | else command is executed when if condition is false. |
Highlight print "Triangle is equilateral" | print command displays the string after checking the else condition. |
Highlight go 100,100 | go 100,100 commands Turtle to go 100 pixels from left of canvas and 100 pixels from top of canvas |
Highlight repeat 3{turnright 120 forward 100} | repeat 3{turnright 120 forward 100} commands Turtle to draws an equilateral triangle on the canvas |
Run the program | Let me run the program to check all the conditions |
Run the program | Press F5 key to run the code.
Enter 6 for length of AB and click OK 5 BC for length of and click OK 7 for AC length of and click OK “Triangle is not equilateral” is displayed on the canvas. |
Run the program | Let's run again
Enter 5 for length of AB and click OK 5 for BC length of and click OK 5 for AC length of and click OK “Triangle is equilateral” is displayed on the canvas. An equilateral triangle is drawn on the canvas. |
With this we come to the end of this tutorial.
Let's summarize. | |
Slide Number 6
Summary |
In this tutorial we have learnt, the question glues
|
Slide Number 7
Assignment |
As an assignment, I would like you to write program to determine
Angle concept for a right angled triangle using question glue “or” |
Slide Number 8
Syntax of if or condition if ((condition)or(condition)or(condition)){ //do something } else { //do something } |
Structure of if or condition is: if within brackets condition or within brackets condition or within brackets condition. Within curly brackets do something. else within curly brackets do something. |
Slide number 8
Acknowledgement |
Watch the video available at this URL
http://spoken-tutorial.org/What is a Spoken Tutorial It summarises the Spoken Tutorial project If you do not have good bandwidth, you can download and watch it |
Slide Number 9 | The Spoken Tutorial Project Team :
Conducts workshops using spoken tutorials Gives certificates to those who pass an online test For more details, please write to contact@spoken-tutorial.org |
Slide number 10 | Spoken Tutorial Project is a part of the Talk to a Teacher project.
It is supported by the National Mission on Education through ICT, MHRD, Government of India More information on this Mission is available at this link http://spoken-tutorial.org/NMEICT-Intro ] This is Madhuri Ganpathi from IIT Bombay signing off. Thank you for joining |