Sunday, 10 June 2012

tinker: . . to work unskillfully or clumsily at anything: . . . tk-tinker is still working itself out . . .  "Learning about computer programming is like learning to play a musical instrument: you have to do it,"

Thursday, 31 May 2012

Python Utility Robot - Python Learning Environment



PUR-PLE

RUR-PLE is an environment designed to help you learn computer programming using the language Python.

Highly recommended ... working through the lessons.



Rule # 1
Learning about computer programming is like learning to play a musical instrument: you have to do it, not simply read about it. 

Rule # 2
Write your computer programs to make them easy for people to read

Rule # 3
When writing computer programs, do not repeat yourself.
I repeat: do not repeat yourself!

The following extract is an example of the interesting content of the lessons.

Picture adapted from the public archive of the U.S. Naval Historical Center 
The project is current and the windows installer is seamless. 
Je trouve le navigateur de RUR-PLE suffire. En fait, je viens de charger 2 instances de RUR-PLE à travailler sur les exercices.

 

Saturday, 26 May 2012

turtle from Python Interpreter

http://docs.python.org/library/turtle.html

To activate turtle from Python Interpreter enter:

from turtle import *
# This imports Turtle and all of its commands.

turtle commands:

forward(distance)

 - Moves the turtle forward by the specified distance, in the direction the turtle is headed.

backward(distance)
- Move the turtle backward by distance, opposite to the direction the turtle is headed. Does not change the turtle’s heading.


right(angle) - Turn turtle right by angle units. (Units are by default degrees)

left(angle)
- Turn turtle left by angle units. (Units are by default degrees)

 goto (x,y)
     or
setposition (x,y)

-  Moves the turtle to coordinates (x,y) and if the pen is down, draw a line.

home( )

-  Moves the turtle back to (0,0)


circle
(radius, extent)
- Draws a circle with radius.
- extent refers to the number of degrees (e.g. 180 = semicircle)


 undo( )
- Undo (repeatedly) the last turtle action.
speed(speed)
 - Sets how fast the turtle will draw (1-10 arbitrary units)


position( )
- Returns the (x,y) coordinates of the turtle.


pendown( )
- Puts the pen down so it draws when the turtle moves.

penup( )
- Puts the pen up so it does not draw when the turtle moves.


pencolor(colorstring)
-  if colorstring == a color like "green" it will draw the line in that color.


reset( )

- Delete everything and set turtle back to 0


clear()
- Delete drawings but keeps turtle where it is.

 

Friday, 25 May 2012

>>> help()

maybe help ( ) can reduce my dependence on the internet
 
Welcome to Python 2.7!  This is the online help utility

If this is your first time using Python, you should definitely check out
the tutorial on the Internet at http://docs.python.org/tutorial/.

Enter the name of any module, keyword, or topic to get help on writing
Python programs and using Python modules.  To quit this help utility and
return to the interpreter, just type "quit".

To get a list of available modules, keywords, or topics, type "modules",
"keywords", or "topics".  Each module also comes with a one-line summary
of what it does; to list the modules whose summaries contain a given word
such as "spam", type "modules spam".

help> LISTS
Mutable Sequence Types
**********************

List and ``bytearray`` objects support additional operations that
allow in-place modification of the object. 
 . . . example of help on topics

help> NAMESPACES
Naming and binding
******************

*Names* refer to objects.  Names are introduced by name binding
operations. Each occurrence of a name in the program text refers to
the *binding* of that name established in the innermost function block
containing the use.

A *block* is a piece of Python program text that is executed as a
unit. The following are blocks: a module, a function body, and a class
definition. Each command typed interactively is a block.  A script
file (a file given as standard input to the interpreter or specified
on the interpreter command line the first argument) is a code block.
...  next help with a module

help> turtle
Help on module turtle:

NAME
    turtle

FILE
    c:\python27\lib\lib-tk\turtle.py

DESCRIPTION
    Turtle graphics is a popular way for introducing programming to
    kids. It was part of the original Logo programming language developed
    by Wally Feurzig and Seymour Papert in 1966.
   
    Imagine a robotic turtle starting at (0, 0) in the x-y plane. Give it
    the command turtle.forward(15), and it moves (on-screen!) 15 pixels in
    the direction it is facing, drawing a line as it moves. Give it the
    command turtle.left(25), and it rotates in-place 25 degrees clockwise.
   
    By combining together these and similar commands, intricate shapes and
    pictures can easily be drawn.
   
    ----- turtle.py


help> keywords

Here is a list of the Python keywords.  Enter any keyword to get more help.

and                 elif                if                  print
as                  else                import              raise
assert              except              in                  return
break               exec                is                  try
class               finally             lambda              while
continue            for                 not                 with
def                 from                or                  yield
del                 global              pass               

helpful>

Initializing Lists

empty_list = []

string_list = [ 'a', 'list', 'of', 'strings']

number_list = [ 1, 1., 0]



list_of_lists = [  'empty_list', [ 1, 1., 0], string_list]

list_of_tuples = [ (1, 'a'), ('Fad', 'book'), ('Fade','book') ]








# append method built-in

string_list.append ('or letters')

#  I like lists because
#  they are simple and powerful

concatenating_lists = ['lists', 'are', 'versatile'] + [('and','fun')]

print string_list
print concatenating_lists









 P.Guo web application used as an illustrated print statement. Online Python Tutor
related blog entry