Pippy: Difference between revisions

From OLPC
Jump to navigation Jump to search
(add Pippy page)
 
No edit summary
Line 7: Line 7:
== Math ==
== Math ==


=== apples ===
=== Apples ===
Author: Madeleine Ball
Author: Madeleine Ball
<pre>
<pre>
Line 51: Line 51:
</pre>
</pre>


=== times1 ===
=== Times1 ===
Author: Chris Ball
Author: Chris Ball
<pre>
<pre>
Line 58: Line 58:
</pre>
</pre>


=== times2 ===
=== Times2 ===
Author: Chris Ball
Author: Chris Ball
<pre>
<pre>
Line 91: Line 91:


== String ==
== String ==
=== hello1 ===
=== Hello1 ===
Author: Chris Ball
Author: Chris Ball
<pre>
<pre>
Line 97: Line 97:
</pre>
</pre>


=== hello2 ===
=== Hello2 ===
Author: Chris Ball
Author: Chris Ball
<pre>
<pre>
Line 105: Line 105:


== Graphics ==
== Graphics ==
=== jump ===
=== Jump ===
Author: C. Scott Ananian
Author: C. Scott Ananian
<pre>
<pre>

Revision as of 17:35, 21 August 2007

Pippy is an activity for learning how to program with Python. It looks like this:

(screenshot)

Examples

Math

Apples

Author: Madeleine Ball

print "Let's do math!"

print "On Monday I picked 22 apples. On Tuesday I picked 12."

print "Now I have: ", 22 + 12

print "My brother says he picked twice as many apples last week."

print "This means he picked: ", (22 + 12) * 2

print "I have 3 friends I would like to give apples."

print "One third of my apples is about: ", (22 + 12) / 3

print "Or, more exactly: ", (22.0 + 12.0) / 3.0

Pascal

Author: Madeleine Ball

# Pascal's triangle
lines = 8

vector = [1]

for i in range(1,lines+1):
  vector.insert(0,0)
  vector.append(0)

for i in range(0,lines):
  newvector = vector[:]
  for j in range(0,len(vector)-1):
    if (newvector[j] == 0):
      print "  ",
    else:
      print "%2d" % newvector[j],
    newvector[j] = vector[j-1] + vector[j+1]
  print
  vector = newvector[:]

Times1

Author: Chris Ball

for i in range(1,13):
    print i, "x 4 =", (i*4)

Times2

Author: Chris Ball

number = input("Which times table? ")
for i in range(1,13):
    print i, "x", number, "=", i*number

Python

Function

Author: Chris Ball

def square(x): 
    print x * x

square(3)
square(4)

If

Author: Chris Ball

number = input("Enter a number: ")

if number > 5:
    print "Greater than 5"
elif number < 5:
    print "Less than 5"
else:
    print "Number is 5!"

String

Hello1

Author: Chris Ball

print "Hello everyone!"

Hello2

Author: Chris Ball

name = raw_input("Type your name here: ")
print "Hello " + name + "!"

Graphics

Jump

Author: C. Scott Ananian

# both of these functions should be in the 'basic' package or some such
def clear_scr():
    print '\x1B[H\x1B[J' # clear screen, the hard way.
def wait():
    import time
    time.sleep(0.1)

# jumping man!
# having to escape the backslash is rather unfortunate
# i didn't have to do that in C64 BASIC
for i in xrange(0,50):
    clear_scr()
    print "\\o/"
    print "_|_"
    print "   "
    wait()
    
    clear_scr()
    print "_o_"
    print " | "
    print "/ \\"
    wait()
    
    clear_scr()
    print " o "
    print "/|\\"
    print "| |"
    wait()
    
    clear_scr()
    print "_o_"
    print " | "
    print "/ \\"
    wait()