KTurtle/C3/Question-Glues/English

From Script | Spoken-Tutorial
Revision as of 11:38, 27 December 2012 by Madhurig (Talk | contribs)

Jump to: navigation, search
Zoom text
Visual Cue Narration
Slide Number 1

Hello everybody.

Welcome to this tutorial on Question Glues in KTurtle.
Slide Number 2

Learning Objectives

In this tutorial, we will learn the following question glues
  • and
  • not
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.

http://spoken-tutorial.org

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. The Search bar appears.

In the Search bar, type KTurtle.

Click on the KTurtle 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.


Resume the tutorial after typing the program.

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)){

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 to 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.
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 Enter 5 for 'length of side AB' and click OK

enter 8 for 'length of side BC' and click OK enter 9 for 'length of side AC' and click OK

“A scalene triangle” is displayed on the canvas.

Run the program Let me run the code again
Point to the dialog box. A message dialog box pops up again.

Let me click OK.

Point to the result Enter 5 for 'AB' and click OK

6 for 'BC' and click OK 6 for 'AC' and click OK “Triangle is not a scalene triangle” is displayed on the canvas.

Run the program Let's run the code again.
Point to the result Enter 1 for 'AB' and click OK

1 for 'BC' and click OK 2 for 'AC' and click OK " Does not satisfy triangle's inequality " is displayed on canvas.

Next let's work with the glue word not.
#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 code from the text editor and paste it into KTurtle editor.


Please pause the tutorial here and type the program into your KTurtle editor.



Resume the tutorial after typing the program.
Let me zoom into the program text and explain the program
Highlight reset reset command sets Turtle to its default 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)){

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} command draws an equilateral triangle on the canvas
Run the program Press F5 key run the code.

Enter 6 for AB and click OK 5 BC for and click OK 7 for AC and click OK “Triangle is not equilateral” is displayed on the canvas.

Run the program Press F5 key to run the code.

Enter 4 for AB and click OK 4 for BC and click OK 4 for AC and click OK “Triangle is equilateral” is displayed 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

and not

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

Contributors and Content Editors

Madhurig