Difference between revisions of "KTurtle/C3/Common-Errors-in-KTurtle/English"
Line 4: | Line 4: | ||
|- | |- | ||
||Slide Number 1 | ||Slide Number 1 | ||
− | || | + | ||Hello everybody. |
− | + | ||
− | Hello everybody. | + | |
− | Welcome to this tutorial on Common Errors in KTurtle. | + | Welcome to this tutorial on '''Common Errors''' in '''KTurtle.''' |
|- | |- | ||
||Slide Number 2 | ||Slide Number 2 | ||
− | Learning Objectives | + | '''Learning Objectives''' |
||In this tutorial, we will learn about | ||In this tutorial, we will learn about | ||
− | Syntax errors and | + | * Syntax errors and |
− | Runtime errors | + | |
+ | * Runtime errors | ||
|- | |- | ||
|| Slide Number 3 | || Slide Number 3 | ||
− | System Requirement | + | '''System Requirement''' |
||To record this tutorial I am using, | ||To record this tutorial I am using, | ||
Ubuntu Linux OS v. 12.04. | Ubuntu Linux OS v. 12.04. | ||
Line 24: | Line 23: | ||
|- | |- | ||
||Slide Number 4 | ||Slide Number 4 | ||
− | Pre-requisites | + | |
+ | '''Pre-requisites''' | ||
||We assume that you have basic working knowledge of KTurtle | ||We assume that you have basic working knowledge of KTurtle | ||
Line 32: | Line 32: | ||
|- | |- | ||
|| | || | ||
− | ||First I will explain about Types of errors. | + | ||First I will explain about "Types of errors". |
|- | |- | ||
||Slide Number 5 | ||Slide Number 5 | ||
− | Syntax Errors | + | '''Syntax Errors''' |
||A syntax error is a violation of grammatical rules, of a programming language. | ||A syntax error is a violation of grammatical rules, of a programming language. | ||
+ | |||
Compilation fails when a program has syntax errors. | Compilation fails when a program has syntax errors. | ||
+ | |||
Syntax errors are easy to find and fix. | Syntax errors are easy to find and fix. | ||
− | + | ||
− | Unmatched parentheses, square brackets and curly braces. | + | For Example: |
− | Use of variable that has not been declared. | + | |
− | Missing quotes in strings. | + | * Unmatched parentheses, square brackets and curly braces. |
+ | |||
+ | * Use of variable that has not been declared. | ||
+ | |||
+ | * Missing quotes in strings. | ||
|- | |- | ||
||Switch to KTurtle Application | ||Switch to KTurtle Application | ||
Line 62: | Line 68: | ||
||I already have a program in a text editor. | ||I already have a program in a text editor. | ||
|- | |- | ||
− | ||reset | + | ||'''reset''' |
− | $a=ask "enter any number and click Ok" | + | '''$a=ask "enter any number and click Ok"''' |
− | $r = ask "enter any number and click ok" | + | '''$r = ask "enter any number and click ok"''' |
− | $n = ask "enter any number and click ok" | + | '''$n = ask "enter any number and click ok"''' |
− | $T = $a*($r^$n)*($r^-1) | + | '''$T = $a*($r^$n)*($r^-1)''' |
− | print $T | + | '''print $T''' |
− | ||Let copy the program into Kturtle Editor. | + | ||Let copy the program into '''Kturtle''' Editor. |
− | Please pause the tutorial and type the program into KTurtle editor | + | Please pause the tutorial and type the program into '''KTurtle''' editor |
Line 80: | Line 86: | ||
|- | |- | ||
|| | || | ||
− | ||To explain | + | ||To explain error in the program, I will delete part of the code. |
|- | |- | ||
||Highlight | ||Highlight | ||
− | $a=ask "enter any number and click Ok" | + | '''$a=ask "enter any number and click Ok"''' |
− | ||Here, I will | + | ||Here, I will delete the line '''$a=ask "enter any number and click Ok"''' |
|- | |- | ||
||Run the program | ||Run the program | ||
||Let's Click on Run button to run the program | ||Let's Click on Run button to run the program | ||
+ | |||
Complier shows the following error, | Complier shows the following error, | ||
− | The variable $a was used without first being assigned to a value. | + | |
+ | '''The variable "$a" was used without first being assigned to a value.''' | ||
|- | |- | ||
− | ||Replace the | + | ||Replace the deleted line |
− | ||I will replace the deleted line $a=ask "enter any number and click Ok" | + | ||I will replace the deleted line '''$a=ask "enter any number and click Ok"''' |
|- | |- | ||
||Run the program | ||Run the program | ||
||Let's run again | ||Let's run again | ||
− | |||
− | We see that the program runs without errors. | + | press '''F5''' key to run the program |
+ | |||
+ | We see that the program runs without errors. | ||
|- | |- | ||
|| | || | ||
Line 106: | Line 115: | ||
||I already have a program in a text editor. | ||I already have a program in a text editor. | ||
|- | |- | ||
− | ||reset | + | ||'''reset''' |
− | $degree=ask "enter any angle value and click OK" | + | '''$degree=ask "enter any angle value and click OK"''' |
− | $radian=(pi/180)*$degree | + | '''$radian=(pi/180)*$degree''' |
− | go 50,50 | + | '''go 50,50''' |
− | print "Value in radians is"+ " " +$radian | + | '''print "Value in radians is"+ " " +$radian''' |
− | spritehide | + | '''spritehide''' |
− | ||Let me copy the program into Kturtle Editor | + | ||Let me copy the program into ''' Kturtle''' Editor |
− | Please pause the tutorial and type the program into KTurtle editor | + | Please pause the tutorial and type the program into '''KTurtle''' editor |
Line 124: | Line 133: | ||
|- | |- | ||
||Highlight $ | ||Highlight $ | ||
− | ||Let's delete $ signs in the program. | + | ||Let's delete '''$''' signs in the program. |
|- | |- | ||
|| | || | ||
Run the program | Run the program | ||
||Let's Click on Run button to run the program. | ||Let's Click on Run button to run the program. | ||
+ | |||
Complier shows the following error, | Complier shows the following error, | ||
− | you cannot put “=” here | + | |
+ | '''you cannot put “=” here''' | ||
|- | |- | ||
− | ||Replace $ signs | + | ||Replace '''$''' signs |
− | ||Let's replace the $ signs and run again. | + | ||Let's replace the '''$''' signs and run again. |
Program runs properly | Program runs properly | ||
|- | |- | ||
− | ||Highlight "Value in radians is" | + | ||Highlight '''"Value in radians is"''' |
− | ||Let's remove | + | ||Let's remove one of the quotes of the string. |
|- | |- | ||
||Run the program | ||Run the program | ||
− | ||Let's click on Run button to run the program | + | ||Let's click on '''Run''' button to run the program |
Complier shows the following error, | Complier shows the following error, | ||
− | text string was not properly closed, expected a double quote “ ” to close the string. | + | '''text string was not properly closed, expected a double quote “ ” to close the string.''' |
|- | |- | ||
||Repalce the quotes | ||Repalce the quotes | ||
||Let's replace the quotes and run again. | ||Let's replace the quotes and run again. | ||
− | press F5 key run the program. | + | |
+ | press '''F5''' key run the program. | ||
+ | |||
program runs without errors. | program runs without errors. | ||
|- | |- | ||
Line 154: | Line 167: | ||
Runtime errors | Runtime errors | ||
||Run-time error occurs during the execution of a program. | ||Run-time error occurs during the execution of a program. | ||
+ | |||
It may crash the program when you run it. | It may crash the program when you run it. | ||
+ | |||
Runtime errors are commonly due to wrong input from the user. | Runtime errors are commonly due to wrong input from the user. | ||
+ | |||
Compiler cannnot find these errors. | Compiler cannnot find these errors. | ||
+ | |||
For example: | For example: | ||
* Trying to multiply or divide by a variable that contains no value. | * Trying to multiply or divide by a variable that contains no value. | ||
+ | |||
* Run a loop without a condition or increment. | * Run a loop without a condition or increment. | ||
|- | |- | ||
|| | || | ||
− | ||Next we will look at errors related to print command | + | ||Next we will look at errors related to '''print''' command |
|- | |- | ||
|| | || | ||
||I already have a program in a text editor. | ||I already have a program in a text editor. | ||
|- | |- | ||
− | ||reset | + | ||'''reset''' |
− | $C= ask "enter any number in celsius scale and click OK" | + | |
− | message "$F is Fahrenheit" | + | '''$C= ask "enter any number in celsius scale and click OK"''' |
− | $F=(9/5*$C)+32 | + | |
− | go 40,40 | + | '''message "$F is Fahrenheit"''' |
− | print "Value in Fahrenheit =" +" "+ $F+"F" | + | |
+ | '''$F=(9/5*$C)+32''' | ||
+ | |||
+ | '''go 40,40''' | ||
+ | |||
+ | '''print "Value in Fahrenheit =" +" "+ $F+"F"''' | ||
||Let me copy the program into Kturtle Editor | ||Let me copy the program into Kturtle Editor | ||
− | Please pause the tutorial and type the program into KTurtle editor | + | Please pause the tutorial and type the program into '''KTurtle''' editor |
Line 184: | Line 207: | ||
It may possibly be a little blurred. | It may possibly be a little blurred. | ||
|- | |- | ||
− | ||Highlight "Value in Kelvin ="+ $K + "K" and delete | + | ||Highlight '''"Value in Kelvin ="+ $K + "K"''' and delete |
− | ||Let's delete line after the keyword print "Value in Kelvin ="+ $K + "K" | + | ||Let's delete line after the keyword '''print''' '''"Value in Kelvin ="+ $K + "K"''' |
|- | |- | ||
||Run the program | ||Run the program | ||
||Let's click on Run button to run the program. | ||Let's click on Run button to run the program. | ||
+ | |||
Complier does not shows any error. | Complier does not shows any error. | ||
Here we get an error as the program runs. | Here we get an error as the program runs. | ||
− | The print command was called with 0 but it needs 1 parameter. | + | |
+ | '''The print command was called with 0 but it needs 1 parameter.''' | ||
+ | |||
It is a runtime error. | It is a runtime error. | ||
|- | |- | ||
||Replace the deleted line | ||Replace the deleted line | ||
+ | |||
Let's replace the deleted line and Run again | Let's replace the deleted line and Run again | ||
program runs without runtime errors. | program runs without runtime errors. | ||
− | |||
− | |||
− | |||
− | |||
− | |||
|- | |- | ||
|| | || | ||
− | ||Next let's look | + | ||Next let's look at run time errors in '''loops.''' |
|- | |- | ||
|| | || | ||
||I already have a program in a text editor. | ||I already have a program in a text editor. | ||
|- | |- | ||
− | ||#program to find multiples of 2 | + | ||'''#program to find multiples of 2''' |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | Please pause the tutorial and type the program into KTurtle editor | + | '''reset''' |
+ | |||
+ | '''$x=0''' | ||
+ | |||
+ | '''message"In while loop, code inside the loop repeats till boolean evaluates false"''' | ||
+ | |||
+ | '''while $x<20 {''' | ||
+ | |||
+ | '''$x=$x+2''' | ||
+ | |||
+ | '''$x=$x*1''' | ||
+ | |||
+ | '''fontsize 15''' | ||
+ | |||
+ | '''forward 20''' | ||
+ | |||
+ | '''print $x | ||
+ | }''' | ||
+ | ||Let copy the program into '''Kturtle''' Editor | ||
+ | |||
+ | Please pause the tutorial and type the program into '''KTurtle''' editor | ||
Line 232: | Line 263: | ||
||Zoom text | ||Zoom text | ||
||Let me zoom into the program text. | ||Let me zoom into the program text. | ||
+ | |||
It may possibly be a little blurred. | It may possibly be a little blurred. | ||
|- | |- | ||
− | ||Highlight $x=$x+2 | + | ||Highlight '''$x=$x+2''' and '''$x=$x*1''' |
− | $x=$x*1 | + | ||Let's delete the lines '''$x=$x+2''' and ''' $x=$x*1''' |
− | ||Let's delete | + | |
|- | |- | ||
||Run the program | ||Run the program | ||
− | ||Let's click on the Run button to run the program. | + | ||Let's click on the '''Run''' button to run the program. |
+ | |||
Complier does not show any error. | Complier does not show any error. | ||
− | We get | + | We get a runtime error. |
Loop become an infinite loop of zeros. | Loop become an infinite loop of zeros. | ||
|- | |- | ||
||Abort the process | ||Abort the process | ||
− | ||I will click on Abort button to abort the process. | + | ||I will click on '''Abort''' button to abort the process. |
|- | |- | ||
||Undo the deleted line | ||Undo the deleted line | ||
− | ||Let's undo the deleted line and Run again | + | ||Let's undo the deleted line and '''Run''' again |
program runs properly as expected. | program runs properly as expected. | ||
Line 260: | Line 292: | ||
||I already have a program in a text editor. | ||I already have a program in a text editor. | ||
|- | |- | ||
− | reset | + | '''reset''' |
− | $x=8 | + | |
− | $r = 1 | + | '''$x=8''' |
− | for $i = 1 to $x { | + | |
− | $r = $r * $i | + | '''$r = 1''' |
− | forward 20 | + | |
− | print $r | + | '''for $i = 1 to $x {''' |
− | } | + | |
− | ||Let copy the program into | + | '''$r = $r * $i''' |
+ | |||
+ | '''forward 20''' | ||
+ | |||
+ | '''print $r | ||
+ | }''' | ||
+ | ||Let copy the program into '''KTurtle''' Editor. | ||
− | Please pause the tutorial and type the program into KTurtle editor | + | Please pause the tutorial and type the program into '''KTurtle''' editor |
Line 279: | Line 317: | ||
It may possibly be a little blurred. | It may possibly be a little blurred. | ||
|- | |- | ||
− | Highlight $r = $r * $i and | + | Highlight '''$r = $r * $i''' and print $r |
− | print $r | + | ||Let's delete the lines ''' $r = $r * $i''' and '''print $r''' |
− | ||Let's delete the lines | + | |
|- | |- | ||
||Run the program | ||Run the program | ||
||Let's click on the Run button to run the program. | ||Let's click on the Run button to run the program. | ||
+ | |||
Complier does not show any error. | Complier does not show any error. | ||
− | We get | + | We get a runtime error. |
We see that only the Turtle has moved forward. | We see that only the Turtle has moved forward. | ||
− | “for” loop is not executed. | + | '''“for”''' loop is not executed. |
|- | |- | ||
||Undo the deleted line | ||Undo the deleted line | ||
− | ||Let's undo the deleted lines | + | ||Let's undo the deleted lines and Run again. |
− | + | Program runs properly as expected. | |
|- | |- | ||
|| | || | ||
Line 305: | Line 343: | ||
Summary | Summary | ||
||In this tutorial we have learnt, errors such as | ||In this tutorial we have learnt, errors such as | ||
− | Use of variable that has not been declared. | + | |
− | Missing quotes in strings. | + | * Use of variable that has not been declared. |
− | Errors related to print command | + | |
− | Runtime errors | + | * Missing quotes in strings. |
+ | |||
+ | * Errors related to print command | ||
+ | |||
+ | * Runtime errors | ||
|- | |- | ||
||Slide Number 10 | ||Slide Number 10 | ||
− | Assignment | + | '''Assignment''' |
− | As an assignment I would like you to find errors in the given programs- | + | ||As an assignment I would like you to find errors in the given programs- |
|- | |- | ||
− | ||Assignment 1 | + | ||'''Assignment 1''' |
− | ||reset | + | ||'''reset''' |
− | $x=3 | + | |
− | $y=3 | + | '''$x=3''' |
− | if $x==$y | + | |
− | print"they are equal" | + | '''$y=3''' |
− | else | + | |
+ | '''if $x==$y''' | ||
+ | |||
+ | '''print"they are equal"''' | ||
+ | |||
+ | '''else''' | ||
{ | { | ||
− | print "they are not equal"} | + | |
+ | '''print "they are not equal"'''} | ||
|- | |- | ||
− | ||Assignment 2 | + | ||'''Assignment 2''' |
− | ||program to find the nth term and sum of n terms in GP | + | ||'''program to find the nth term and sum of n terms in GP''' |
− | reset | + | |
− | $x=ask "enter value for x and click Ok" | + | '''reset''' |
− | $y = ask "enter value for y and click Ok" | + | |
− | $g =sqrt ($x*$y) | + | '''$x=ask "enter value for x and click Ok"''' |
− | print "Geometric mean is ="+ | + | |
+ | '''$y = ask "enter value for y and click''' Ok" | ||
+ | |||
+ | '''$g =sqrt ($x*$y)''' | ||
+ | |||
+ | '''print "Geometric mean is ="+''' | ||
|- | |- | ||
− | ||Assignment 3 | + | ||'''Assignment 3''' |
− | ||reset | + | ||'''reset''' |
− | learn sum $x { | + | '''learn sum $x {''' |
− | {$r=0 | + | '''{$r=0''' |
− | for $i= 1 to $x{ | + | '''for $i= 1 to $x{''' |
− | return $r} | + | '''return $r}''' |
} | } | ||
− | print | + | '''print''' |
|- | |- | ||
||Slide number 11 | ||Slide number 11 |
Revision as of 17:40, 10 January 2013
Visual Cue | Narration |
---|---|
Slide Number 1 | Hello everybody.
Welcome to this tutorial on Common Errors in KTurtle. |
Slide Number 2
Learning Objectives |
In this tutorial, we will learn about
|
Slide Number 3
System Requirement |
To record this tutorial I am using,
Ubuntu Linux OS v. 12.04. KTurtle v. 0.8.1 beta. |
Slide Number 4
Pre-requisites |
We assume that you have basic working knowledge of KTurtle
If not, for relevant tutorials, please visit our website. http://spoken-tutorial.org |
First I will explain about "Types of errors". | |
Slide Number 5
Syntax Errors |
A syntax error is a violation of grammatical rules, of a programming language.
Compilation fails when a program has syntax errors. Syntax errors are easy to find and fix. For Example:
|
Switch to KTurtle Application
Dash home >>Search bar appears>> In the Search bar type KTurtle Click on the KTurtle icon. |
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 icon. |
Let's begin the tutorial with some types of syntax errors. | |
I already have a program in a text editor. | |
reset
$a=ask "enter any number and click Ok" $r = ask "enter any number and click ok" $n = ask "enter any number and click ok" $T = $a*($r^$n)*($r^-1) print $T |
Let copy the program into Kturtle Editor.
Please pause the tutorial and type the program into KTurtle editor
|
Zoom text | Let me zoom into the program text.
It may possibly be a little blurred. |
To explain error in the program, I will delete part of the code. | |
Highlight
$a=ask "enter any number and click Ok" |
Here, I will delete the line $a=ask "enter any number and click Ok" |
Run the program | Let's Click on Run button to run the program
Complier shows the following error, The variable "$a" was used without first being assigned to a value. |
Replace the deleted line | I will replace the deleted line $a=ask "enter any number and click Ok" |
Run the program | Let's run again
press F5 key to run the program We see that the program runs without errors. |
Next let's look at another type of error. | |
I already have a program in a text editor. | |
reset
$degree=ask "enter any angle value and click OK" $radian=(pi/180)*$degree go 50,50 print "Value in radians is"+ " " +$radian spritehide |
Let me copy the program into Kturtle Editor
Please pause the tutorial and type the program into KTurtle editor
|
Zoom text | Let me zoom into the program text.
It may possibly be a little blurred. |
Highlight $ | Let's delete $ signs in the program. |
Run the program |
Let's Click on Run button to run the program.
Complier shows the following error, you cannot put “=” here |
Replace $ signs | Let's replace the $ signs and run again.
Program runs properly |
Highlight "Value in radians is" | Let's remove one of the quotes of the string. |
Run the program | Let's click on Run button to run the program
Complier shows the following error, text string was not properly closed, expected a double quote “ ” to close the string. |
Repalce the quotes | Let's replace the quotes and run again.
press F5 key run the program. program runs without errors. |
Slide Number 6
Runtime errors |
Run-time error occurs during the execution of a program.
It may crash the program when you run it. Runtime errors are commonly due to wrong input from the user. Compiler cannnot find these errors. For example:
|
Next we will look at errors related to print command | |
I already have a program in a text editor. | |
reset
$C= ask "enter any number in celsius scale and click OK" message "$F is Fahrenheit" $F=(9/5*$C)+32 go 40,40 print "Value in Fahrenheit =" +" "+ $F+"F" |
Let me copy the program into Kturtle Editor
Please pause the tutorial and type the program into KTurtle editor
|
Zoom text
Let me zoom into the program text. It may possibly be a little blurred. | |
Highlight "Value in Kelvin ="+ $K + "K" and delete | Let's delete line after the keyword print "Value in Kelvin ="+ $K + "K" |
Run the program | Let's click on Run button to run the program.
Complier does not shows any error. Here we get an error as the program runs. The print command was called with 0 but it needs 1 parameter. It is a runtime error. |
Replace the deleted line
Let's replace the deleted line and Run again program runs without runtime errors. | |
Next let's look at run time errors in loops. | |
I already have a program in a text editor. | |
#program to find multiples of 2
reset $x=0 message"In while loop, code inside the loop repeats till boolean evaluates false" while $x<20 { $x=$x+2 $x=$x*1 fontsize 15 forward 20 print $x } |
Let copy the program into Kturtle Editor
Please pause the tutorial and type the program into KTurtle editor
|
Zoom text | Let me zoom into the program text.
It may possibly be a little blurred. |
Highlight $x=$x+2 and $x=$x*1 | Let's delete the lines $x=$x+2 and $x=$x*1 |
Run the program | Let's click on the Run button to run the program.
Complier does not show any error. We get a runtime error. Loop become an infinite loop of zeros. |
Abort the process | I will click on Abort button to abort the process. |
Undo the deleted line | Let's undo the deleted line and Run again
program runs properly as expected. |
Let's now try another example for runtime error. | |
I already have a program in a text editor. | |
Let copy the program into KTurtle Editor.
Please pause the tutorial and type the program into KTurtle editor
| |
Zoom text | Let me zoom into the program text.
It may possibly be a little blurred. |
Let's delete the lines $r = $r * $i and print $r | |
Run the program | Let's click on the Run button to run the program.
Complier does not show any error. We get a runtime error. We see that only the Turtle has moved forward. “for” loop is not executed. |
Undo the deleted line | Let's undo the deleted lines and Run again.
Program runs properly as expected. |
With this we come to the end of this tutorial.
let us summarise. | |
Slide Number 9
Summary |
In this tutorial we have learnt, errors such as
|
Slide Number 10
Assignment |
As an assignment I would like you to find errors in the given programs- |
Assignment 1 | reset
$x=3 $y=3 if $x==$y print"they are equal" else { print "they are not equal"} |
Assignment 2 | program to find the nth term and sum of n terms in GP
reset $x=ask "enter value for x and click Ok" $y = ask "enter value for y and click Ok" $g =sqrt ($x*$y) print "Geometric mean is ="+ |
Assignment 3 | reset
learn sum $x { {$r=0 for $i= 1 to $x{ return $r} } print |
Slide number 11
Acknowledgement |
Watch the video available at
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 12 |
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 13 | 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 http://spoken-tutorial.org/NMEICT-Intro ] This is Madhuri Ganpathi from IIT Bombay Thank you for joining |