Difference between revisions of "KTurtle/C3/Programming-Concepts/English"

From Script | Spoken-Tutorial
Jump to: navigation, search
 
(17 intermediate revisions by the same user not shown)
Line 1: Line 1:
 +
Title of the tutorial: Programming-Concepts
 +
 +
Author: Madhuri Ganpathi
 +
 +
Key words: Variables, print command, canvas, Comment a line, sprite, spritehide, spriteshow, clear, video tutorial.
 +
 
{|border =1
 
{|border =1
 
!Visual Cue
 
!Visual Cue
Line 6: Line 12:
 
||Hello Everybody.  
 
||Hello Everybody.  
 
    
 
    
Welcome to this tutorial on Programming concepts in KTurtle.
+
Welcome to this tutorial on '''Programming concepts''' in '''KTurtle'''.
  
 
|-
 
|-
 
||Slide  Number 2
 
||Slide  Number 2
  
Learning Objectives
+
'''Learning Objectives'''
 
||
 
||
 
In this tutorial, we will learn how to
 
In this tutorial, we will learn how to
Line 26: Line 32:
 
|| Slide Number 3
 
|| Slide Number 3
  
System Requirement
+
'''System Requirement'''
  
  
Line 37: Line 43:
 
||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. '''  
  
 
If not,  
 
If not,  
Line 49: Line 55:
 
|-
 
|-
 
||
 
||
||Before proceeding, we will discuss some basic information about KTurtle.
+
||Before proceeding, we will discuss some basic information about '''KTurtle'''.
 
|-
 
|-
 
||Slide Number 5
 
||Slide Number 5
  
Sprite  
+
'''Sprite '''
||Turtle displayed on the canvas is called sprite.  
+
||"Turtle" displayed on the canvas is called "sprite".  
  
Sprite is a small image that moves around the screen.
+
"Sprite" is a small image that moves around the screen.
  
 
e.g.  Cursor is a sprite.
 
e.g.  Cursor is a sprite.
Line 62: Line 68:
 
||Slide Number 6  
 
||Slide Number 6  
  
sprite Commands
+
'''sprite Commands'''
||Spritehide command hides Turtle from canvas.
+
||"spritehide" command hides '''Turtle''' from canvas.
  
Spriteshow command shows Turtle if it is hidden.  
+
"spriteshow" command shows '''Turtle''' if it is hidden.  
  
Clear command cleans all drawings from canvas.
+
"clear" command cleans all drawings from canvas.
 
|-
 
|-
 
||Slide Number 7
 
||Slide Number 7
 
Symbols
 
Symbols
||In KTurtle,   
+
||In '''KTurtle''',   
$ sign is a container of variables.
+
"$ " sign is a container of variables.
 +
 
 
"*"(asterisk) is used for multiplication of two numbers.   
 
"*"(asterisk) is used for multiplication of two numbers.   
"^"(caret) raises the power of a number.
+
 
 +
"^"(caret) raises the power of the number.
 +
 
 
"#"(hash) sign comments a line written after it.
 
"#"(hash) sign comments a line written after it.
 +
 
"sqrt" is an inbuilt function to find square root of a number.
 
"sqrt" is an inbuilt function to find square root of a number.
 
|-
 
|-
||Switch to Kturtle Application
+
||Switch to '''Kturtle''' Application
Dash  home >>Media Apps>>Under Type         >>Education>>KTurtle
+
'''Dash  home >>Media Apps>>Under Type >>Education>>KTurtle'''
 
+
  
||Let's open  new  KTurtle Application
+
||Let's open  new  '''KTurtle''' Application
Click on  Dash  home >> Media Apps.
+
Click on  '''Dash  home''' >> '''Media Apps'''.
  
Under Type, Choose Education and KTurtle.
+
'''Under Type, Choose Education''' and '''KTurtle'''.
KTurtle application opens.
+
'''KTurtle''' application opens.
 
|-
 
|-
||Press CTRL+ALT+T  >> open the terminal >>type kturtle >>press enter to open
+
||Press '''CTRL+ALT+T''' >> open the '''terminal''' >>type kturtle >>press enter to open
||We can also open  KTurtle Application from the terminal.
+
||We can also open  '''KTurtle''' using '''terminal'''.
Press CTRL+ALT+T simultaneously to open the terminal.
+
Press '''CTRL+ALT+T''' simultaneously to open the terminal.
Type KTurtle and press enter,  KTurtle Application opens.
+
Type '''KTurtle''' and press enter,  '''KTurtle''' Application opens.
 
|-
 
|-
 
||
 
||
Line 97: Line 106:
 
|-
 
|-
 
||
 
||
||Let me zoom the program text, it may possibly be a little blurred.
+
||Let me zoom into the program text, it may possibly be a little blurred.
 
|-
 
|-
||#program to find square of a number
+
||'''#program to find square of a number'''
 
Highlight #
 
Highlight #
||#program to find square of a number. Press enter
+
||'''#program to find square of a number'''. Press enter
  
 
"#" sign comments a line written after it.  
 
"#" sign comments a line written after it.  
 +
 
This means, this line will not be executed while running the program. Press enter.
 
This means, this line will not be executed while running the program. Press enter.
 
|-
 
|-
||reset
+
||'''reset'''
 
Highlight reset
 
Highlight reset
||reset
+
||'''reset'''
 +
 
 
reset command sets Turtle to default position. Press enter.
 
reset command sets Turtle to default position. Press enter.
 
|-
 
|-
||$i= ask  "enter any number for i and click OK"      
+
||'''$i= ask  "enter any number for i and click OK" '''     
  
 
Highlight $i
 
Highlight $i
 
||
 
||
$i= ask  within double quotes  enter any number for i and click OK.         
+
'''$i= ask''' within double quotes  '''enter any number for i and click OK'''.         
  
$i is a variable to store user input.
+
"$i" is a variable to store user input.
 
|-
 
|-
||Highlight ask
+
||Highlight '''"ask"'''
||“ask”  command asks for user input to be stored in variable
+
||'''“ask”''' command asks for user input to be stored in variable
 
press enter
 
press enter
 
|-
 
|-
||fontsize 28
+
||'''fontsize 28'''
  
Highlight fontsize 28
+
Highlight '''fontsize 28'''
||“fontsize” space 28  press enter.
+
||'''“fontsize”''' space '''28'''  
  
fontsize 28  sets the font size used by print.  
+
'''fontsize 28''' sets the font size used by print.  
 
Fontsize takes number as input, set in pixels.
 
Fontsize takes number as input, set in pixels.
 
|-
 
|-
||print $i*$i   
+
||'''print $i*$i'''  
  
Highlight print $i*$i  
+
Highlight '''print $i*$i'''
||print $i*$i   
+
||'''print $i*$i'''  
  
print $i*$i calculates and prints square of a number.   
+
'''print $i*$i''' calculates and prints square of a number.   
 
press enter.
 
press enter.
  
 
|-
 
|-
||spritehide
+
||'''spritehide'''
Highlight spritehide
+
Highlight '''spritehide'''
||spritehide
+
||'''spritehide'''
spritehide hides Turtle from canvas.
+
 
 +
'''spritehide''' hides '''Turtle''' from canvas.
 
|-
 
|-
 
||Run the program code
 
||Run the program code
 
||Let us Run the program now.
 
||Let us Run the program now.
Click on Run button on the toolbar to start execution of the code in the editor.
+
Click on '''Run''' button on the toolbar to start execution of the code in the editor.
 
It shows a list of execution speeds.  
 
It shows a list of execution speeds.  
Full speed(no highlighting and inspector)
+
'''Full speed(no highlighting and inspector)'''
Full speed,  
+
'''Full speed''',  
slow,  
+
'''slow''',  
slower,
+
'''slower''',
slowest and
+
'''slowest''' and
step-by-step.
+
'''step-by-step'''.
 
|-
 
|-
 
||Enter '15' for i
 
||Enter '15' for i
 +
 
Square of 15 =225
 
Square of 15 =225
||Let me run the code at slow speed.
+
||Let me run the code at '''slow''' speed.
An input bar appears  
+
An "input bar" appears  
 
let's enter  15  for i  and click OK
 
let's enter  15  for i  and click OK
 
square of '15'  = '225' is displayed on the canvas.
 
square of '15'  = '225' is displayed on the canvas.
 
|-
 
|-
 +
||
 
||Let's now learn to find nth power of a number through a  program.
 
||Let's now learn to find nth power of a number through a  program.
 +
|-
 +
||
 
||I already have program  in a text editor.  
 
||I already have program  in a text editor.  
 
|-
 
|-
||#Program evaluates  nth power of a number
+
||'''#Program evaluates  nth power of a number
reset  
+
'''reset'''
$i= ask "enter number  for  i and click OK"  
+
'''$i= ask "enter number  for  i and click OK"'''
$n=ask "enter number for n and click OK"  
+
'''$n=ask "enter number for n and click OK"'''
fontsize 28  
+
'''fontsize 28'''
print  ($i^$n)  
+
'''print  ($i^$n)'''
spritehide
+
'''spritehide'''
||Let me copy the code from editor and paste it into  KTurtle editor.  
+
||Let me copy the code from text editor and paste it into  '''KTurtle's''' editor.
 +
 
 +
 
 +
Please pause the tutorial here and copy the program into your '''KTurtle''' editor.
 +
|-
 +
||
 +
||Let me zoom into the program text.
 +
|-
 +
||
 +
||Explain the program.
 +
|-
 +
||Highlight #
 +
||# sign comments a line written after it.
 +
|-
 +
||Highlight '''reset'''
 +
||'''reset''' command sets '''Turtle''' to '''default''' position.
 +
|-
 +
||Highlight '''$i''' and '''$n'''
 +
||'''$i''' and '''$n''' are variables to store user input.
 +
|-
 +
||Highlight '''ask'''
 +
||'''“ask”''' command asks for user input to be stored in variables.
 +
|-
 +
||Highlight '''fontsize 28'''
 +
||'''fontsize 28'''  sets the font size used by print.
 +
Fontsize takes number as input, set in pixels.
 +
|-
 +
||Highlight '''print ($i^$n)'''
 +
||'''print ($i^$n)''' calculates & prints nth power of a number.
 +
|-
 +
||Highlight '''spritehide'''
 +
||'''spritehide''' hides '''Turtle''' from canvas.
 +
|-
 +
||Run the program code
 +
||Let's  run the program.
 +
 
 +
Let's enter '5'  for i, and click OK
 +
Let's enter  '4' for n, and click OK
 +
5^4=625  is displayed on the canvas.
 +
|-
 +
||
 +
||Next, let's use inbuilt '''“sqrt”''' function in a program to find square root of a number.
 +
|-
 +
||'''#Program finds square root of a positive number'''
 +
'''reset'''
 +
'''$i= ask "enter number for  i and click OK"'''
 +
'''fontsize 28'''
 +
'''print sqrt $i'''
 +
'''spritehide'''
 +
 
 +
||Let me copy the code from text editor and paste it into ''' KTurtle's''' editor.
 +
 
 +
 
 +
Please pause the tutorial here and copy the program into your '''KTurtle''' editor.
 +
 
 +
|-
 +
||
 +
||Let me zoom the program text it may possibly be a little blurred.
 +
|-
 +
||
 +
||Let me explain the code now.
 +
 
 +
|-
 +
||Highlight #
 +
||# sign comments a line written after it .
 +
|-
 +
||Highlight '''reset'''
 +
||'''reset''' command sets '''Turtle''' to '''default''' position.
 +
|-
 +
||Highlight '''$i'''
 +
||'''$i''' is a variable to store user input.
 +
|-
 +
||Highlight '''fontsize 28'''
 +
||'''fontsize 28'''  sets the font size used by print.
 +
|-
 +
||Highlight''' print sqrt $i'''
 +
||'''print sqrt $i''' prints square root of a number.
 +
|-
 +
||Highlight '''spritehide'''
 +
||'''spritehide''' hides '''Turtle''' from canvas.
 +
|-
 +
||'''Run the program code'''
 +
||Let me run the program now.
 +
Let's enter  '169'  for i,  and click OK
 +
square root of 169 = 13,
 +
is displayed on canvas.
 +
|-
 +
||'''Run the program code'''
 +
||Let's  run again,
 +
let's enter -169  for i and click OK.
 +
If we enter negative number,
 +
output is ''''nan''''  it means not a number.
 +
As square root of negative number is not a real number.
 +
|-
 +
||
 +
||Let's next evaluate Cube root of a positive number through a program.
 +
|-
 +
||'''#Program to find cube root of a positive number'''
 +
'''reset'''
 +
'''$i= ask "enter a number  for i and click OK"'''
 +
'''$C=($i)^(1/3)'''
 +
'''fontsize 28'''
 +
'''print $C'''
 +
'''spritehide'''
 +
||
 +
Let me copy the program from editor and paste it into ''' KTurtle's''' editor.
 +
 
 +
 
 +
 
 +
 
 +
Please pause the tutorial here and copy the program into your '''KTurtle''' editor.
 +
|-
 +
||
 +
 
 +
||Let me zoom into the program text it may possibly be a little blurred.
 +
|-
 +
||
 +
||Let me explain the program.
 +
|-
 +
||Highlight #
 +
||#  sign comments a line.
 +
Please note this is a single line comment.
 +
Every comment must be preceeded by a # sign.
 +
|-
 +
||Highlight '''reset'''
 +
||'''reset''' command sets the '''Turtle''' to '''default''' position.
 +
|-
 +
||Highlight '''$i''' and '''$C'''
 +
||'''$i''' and '''$C''' are  variables to store user input.
 +
|-
 +
||Highlight '''$C=($i)^(1/3)'''
 +
||'''$C=($i)^(1/3)''' calculates cube root of a number.
 +
|-
 +
||Highlight '''fontsize 28'''
 +
||'''fontsize 28'''  sets the font size used by print.
 +
|-
 +
||Highlight '''print $C'''
 +
||'''print $C''' prints cube root of a number.
 +
|-
 +
||Highlight '''spritehide'''
 +
||'''spritehide''' hides '''Turtle''' from canvas.
 +
|-
 +
||'''Run the program'''
 +
||Let's Run the program
 +
 
 +
Let's enter 343 for i and click OK
 +
cube root of 343 = 7
 +
is be displayed on canvas.
 +
|-
 +
||
 +
||With this we have come to the end of this tutorial.
 +
let us summarize.
 +
|-
 +
||Slide number 8
 +
 
 +
'''Summary'''
 +
||In this tutorial, we have learnt
 +
* Programming concepts
 +
 
 +
* Use of sqrt function
 +
 
 +
* Use of print command
 +
 
 +
* Using KTurtle editor and canvas.
 +
|-
 +
||Slide Number 9
 +
 
 +
'''Assignment'''
 +
||As an assignment, I would like you to use basic programming commands to find ...
 +
* Cube of a number
 +
 
 +
* nth root of a number
 +
|-
 +
||Slide number 10
 +
'''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 11
 +
 
 +
||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 12
 +
||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 ].
  
Please pause the tutorial here and copy the program into your KTurtle editor.  
+
This is Madhuri Ganpathi, from IIT Bombay signing off.
 +
Thank you for joining.
 
|-
 
|-

Latest revision as of 15:48, 18 December 2013

Title of the tutorial: Programming-Concepts

Author: Madhuri Ganpathi

Key words: Variables, print command, canvas, Comment a line, sprite, spritehide, spriteshow, clear, video tutorial.

Visual Cue Narration
Slide Number 1 Hello Everybody.

Welcome to this tutorial on Programming concepts in KTurtle.

Slide Number 2

Learning Objectives

In this tutorial, we will learn how to

  • Write a program in KTurtle
  • Use variables to store user input
  • Use print command to print on canvas
  • Comment a line
Slide Number 3

System Requirement


To record this tutorial, I am using,

Ubuntu Linux OS Version 11.10.

KTurtle version 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.

Before proceeding, we will discuss some basic information about KTurtle.
Slide Number 5

Sprite

"Turtle" displayed on the canvas is called "sprite".

"Sprite" is a small image that moves around the screen.

e.g. Cursor is a sprite.

Slide Number 6

sprite Commands

"spritehide" command hides Turtle from canvas.

"spriteshow" command shows Turtle if it is hidden.

"clear" command cleans all drawings from canvas.

Slide Number 7

Symbols

In KTurtle,

"$ " sign is a container of variables.

"*"(asterisk) is used for multiplication of two numbers.

"^"(caret) raises the power of the number.

"#"(hash) sign comments a line written after it.

"sqrt" is an inbuilt function to find square root of a number.

Switch to Kturtle Application

Dash home >>Media Apps>>Under Type >>Education>>KTurtle

Let's open new KTurtle Application

Click on Dash home >> Media Apps.

Under Type, Choose Education and KTurtle. KTurtle application opens.

Press CTRL+ALT+T >> open the terminal >>type kturtle >>press enter to open We can also open KTurtle using terminal.

Press CTRL+ALT+T simultaneously to open the terminal. Type KTurtle and press enter, KTurtle Application opens.

Let me type and explain the program code.
Let me zoom into the program text, it may possibly be a little blurred.
#program to find square of a number

Highlight #

#program to find square of a number. Press enter

"#" sign comments a line written after it.

This means, this line will not be executed while running the program. Press enter.

reset

Highlight reset

reset

reset command sets Turtle to default position. Press enter.

$i= ask "enter any number for i and click OK"

Highlight $i

$i= ask within double quotes enter any number for i and click OK.

"$i" is a variable to store user input.

Highlight "ask" “ask” command asks for user input to be stored in variable

press enter

fontsize 28

Highlight fontsize 28

“fontsize” space 28

fontsize 28 sets the font size used by print. Fontsize takes number as input, set in pixels.

print $i*$i

Highlight print $i*$i

print $i*$i

print $i*$i calculates and prints square of a number. press enter.

spritehide

Highlight spritehide

spritehide

spritehide hides Turtle from canvas.

Run the program code Let us Run the program now.

Click on Run button on the toolbar to start execution of the code in the editor. It shows a list of execution speeds. Full speed(no highlighting and inspector) Full speed, slow, slower, slowest and step-by-step.

Enter '15' for i

Square of 15 =225

Let me run the code at slow speed.

An "input bar" appears let's enter 15 for i and click OK square of '15' = '225' is displayed on the canvas.

Let's now learn to find nth power of a number through a program.
I already have program in a text editor.
#Program evaluates nth power of a number

reset $i= ask "enter number for i and click OK" $n=ask "enter number for n and click OK" fontsize 28 print ($i^$n) spritehide

Let me copy the code from text editor and paste it into KTurtle's editor.


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

Let me zoom into the program text.
Explain the program.
Highlight # # sign comments a line written after it.
Highlight reset reset command sets Turtle to default position.
Highlight $i and $n $i and $n are variables to store user input.
Highlight ask “ask” command asks for user input to be stored in variables.
Highlight fontsize 28 fontsize 28 sets the font size used by print.

Fontsize takes number as input, set in pixels.

Highlight print ($i^$n) print ($i^$n) calculates & prints nth power of a number.
Highlight spritehide spritehide hides Turtle from canvas.
Run the program code Let's run the program.

Let's enter '5' for i, and click OK Let's enter '4' for n, and click OK

5^4=625  is displayed on the canvas. 
Next, let's use inbuilt “sqrt” function in a program to find square root of a number.
#Program finds square root of a positive number

reset $i= ask "enter number for i and click OK" fontsize 28 print sqrt $i spritehide

Let me copy the code from text editor and paste it into KTurtle's editor.


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

Let me zoom the program text it may possibly be a little blurred.
Let me explain the code now.
Highlight # # sign comments a line written after it .
Highlight reset reset command sets Turtle to default position.
Highlight $i $i is a variable to store user input.
Highlight fontsize 28 fontsize 28 sets the font size used by print.
Highlight print sqrt $i print sqrt $i prints square root of a number.
Highlight spritehide spritehide hides Turtle from canvas.
Run the program code Let me run the program now.

Let's enter '169' for i, and click OK square root of 169 = 13, is displayed on canvas.

Run the program code Let's run again,

let's enter -169 for i and click OK. If we enter negative number, output is 'nan' it means not a number. As square root of negative number is not a real number.

Let's next evaluate Cube root of a positive number through a program.
#Program to find cube root of a positive number

reset $i= ask "enter a number for i and click OK" $C=($i)^(1/3) fontsize 28 print $C spritehide

Let me copy the program from editor and paste it into KTurtle's editor.



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

Let me zoom into the program text it may possibly be a little blurred.
Let me explain the program.
Highlight # # sign comments a line.

Please note this is a single line comment. Every comment must be preceeded by a # sign.

Highlight reset reset command sets the Turtle to default position.
Highlight $i and $C $i and $C are variables to store user input.
Highlight $C=($i)^(1/3) $C=($i)^(1/3) calculates cube root of a number.
Highlight fontsize 28 fontsize 28 sets the font size used by print.
Highlight print $C print $C prints cube root of a number.
Highlight spritehide spritehide hides Turtle from canvas.
Run the program Let's Run the program

Let's enter 343 for i and click OK cube root of 343 = 7 is be displayed on canvas.

With this we have come to the end of this tutorial.

let us summarize.

Slide number 8

Summary

In this tutorial, we have learnt
  • Programming concepts
  • Use of sqrt function
  • Use of print command
  • Using KTurtle editor and canvas.
Slide Number 9

Assignment

As an assignment, I would like you to use basic programming commands to find ...
  • Cube of a number
  • nth root of a number
Slide number 10

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 11 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 12 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