KTurtle/C3/Common-Errors-in-KTurtle/English
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. |
Slide Number 5
Definition of Error |
Let's first define, What is an error ?
Error is a mistake in a program that produces an incorrect or unexpected result. |
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 |
I will Copy the program into Kturtle Editor.
Pause the tutorial and type the program your into KTurtle editor
|
Zoom text | Let me zoom into the program text.
It may possibly be a little blurred. |
Comment code | To explain error in the program, I will comment the code. |
Highlight
$a=ask "enter any number and click Ok" |
Here, I will comment 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. |
Highlight Line number 2 | Error is in line number 2. |
Syntax error | This is syntax error. It occured, as the variable 'a' was not declared. |
Highlight $a=ask "enter any number and click Ok"
Remove the comment |
So I will go to line number 2 and remove the comment. |
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 error. | |
I already have a program in a text editor. | |
reset
$degree=ask "enter an angle value and click OK" $radian=(pi/180)*$degree go 50,50 print "Value in radians is"+ " " +$radian spritehide |
I will copy the program into Kturtle Editor
Please pause the tutorial and type the program your into KTurtle editor
|
Zoom text | Let me zoom into the program text.
It may possibly be a little blurred. |
Highlight$radian=(pi/180)*$degree | Value of "pi" is predefined in KTurtle. |
Highlight $ | Let's delete $ sign 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 |
Highlight Line number 2 | Error is in line number 2. |
Show error | This syntax error occured, as there is no container of variables. |
Replace $ sign | Let's replace the $ sign 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. |
Highlight Line number 5 | Error is in line number 5. |
Replace the quotes | So I will go to line number 5 and replace the quotes.
press F5 key to run the program. Program runs without errors. This way you can find the line at which error has occured, and correct it. |
Let's now learn about runtime 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:
|
I already have a program in a text editor. | |
reset
$a=ask "enter a number for 'a' and click Ok" $r = ask "enter a number for 'r' and click OK" $d=$a/$r print $d |
I will copy the program into Kturtle Editor. Pause the tutorial and type the program into your KTurtle editor Resume the tutorial after typing the program. |
Zoom text | I will zoom into the program text.
It may possibly be a little blurred. |
Run the program | Let's click on the Run button to run the program.
Complier does not show any error. Let's enter 5 for 'a' and click OK enter 0 for 'r' and click OK Here we get a runtime error, “ you tried to divide by zero” |
Highlight Line number 4 | Here error is in line number 4. |
Run time error | This error occurs as we cannot divide a number with zero. |
Next we will learn about logical errors. | |
Logical errors | Logical error is a mistake in a program's source code that results in incorrect or unexpected behavior.
For example, Assigning a value to the wrong variable. Multiplying two numbers instead of adding. |
I already have a program in a text editor. | |
reset
$x=30 message"In while loop, code inside the loop repeats till boolean evaluates false" while $x>20 { $x=$x+1 fontsize 15 forward 20 print $x } |
I will copy the program into Kturtle Editor
Pause the tutorial 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. |
Run the program
Highlight “ while” loop condition |
Now click on the Run button to run the program.
Complier does not show any error. Loop goes into an infinite loop. We see that “while” loop prints numbers from 31 and it is still printing. This is a logical error. In this “while” condition x is greater than 20, but the variable x is always greater than 20 So the loop never terminates. |
Abort the process | I will click on Abort button to abort the process. |
Change $x=$x+1 to $x=$x-1 | Let's Change $x=$x+1 to $x=$x-1.
Run again. program runs properly. Loop terminates after printing values from 29 to 20. |
With this we have come to the end of this tutorial.
let us summarise. | |
Slide Number 9
Summary |
In this tutorial we have learnt, errors and types of 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} } |
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 |