Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: Teaching Children How to Program

by GrandFather (Cardinal)
on Nov 13, 2005 at 19:43 UTC ( #508135=note: print w/ replies, xml ) Need Help??


in reply to Teaching Children How to Program

You timed this question very well! Yesterday our 12 year old son asked me how to write script for a game system (Morrowind). So I signed him up with PerlMonks and pointed him at the tutorials section. He started with baby steps. We managed to skip over most of the stuff about getting Perl installed etc., down to the hello world - which of course was a little more interesting when we substituted his name.

After that it was mostly feeding him little bits to augment the stuff he was reading in the tutorial. For example, at one point he wanted to check that a reply was a number, so I wrtoe a "magic" isNumber sub for him using some regex "magic". He was very happy with the magic, and spent the rest of the afternoon writing Perl to ask questions (sometimes in a loop for a "correct" answer), check answers and do simple arithmetic ("Half your age is ...").

At the end of the afternoon he knew about variables, print, <STDIN>, chomp, eq, ne, lc, last, redo, strings and interpolation (although not explicitly, just through use) and probably other stuff I don't remember. He is also keen to learn more. He was very keen to post his "first program" to PerlMonks. Anyone want to suggest a suitable section (Meditations perhaps), but I disuaded him - somewhat reluctantly.

If anyone wants to /msg Panda, he'd probably be quite excited :)


Perl is Huffman encoded by design.


Comment on Re: Teaching Children How to Program
Re^2: Teaching Children How to Program
by Panda (Scribe) on Nov 14, 2005 at 09:54 UTC

    This is the first program I made. It's relatively simple but it helped me understand the basics.

    use warnings; use strict; print "What is your name?"; my $name = <STDIN>; chomp $name; print "Hello, $name:)\n"; print "How old are you? "; my $age = <STDIN>; chomp $age; print "You are $age years old!\n"; $age = $age / 2; print "Half your age is $age years.\n"; my $sum; { print "Enter a number... "; $sum = <STDIN>; chomp $sum; if (! isNumber ($sum)) { print "Please use numrals.\n"; redo; } else { last; } } my $nextsum = $sum / 2; print "Half of $sum = $nextsum"; sub isNumber { my $value = shift; return $value =~ /^[.\d+-eE]+$/; }; print "\nTell me $name, would you like to try a test? Yes or No.\n"; { my $answer = <STDIN>; chomp $answer; if ("no" eq lc ($answer)) { print "Oh well, have a good day!"; exit; } if ("yes" ne lc ($answer)) { print "Please answer yes or no $name\n"; redo; } } print "The question is: What is the square root of 36?\n"; my $answertwo = <STDIN>; chomp $answertwo; print "Correct! Have a good day!" if "6" eq lc ($answertwo); print "Sorry, you're wrong. Have a good day!" if "6" ne lc ($answertwo +);

    As you can see, it goes like this:

    What is your name?your name Hello, your name:) How old are you? 34 You are 34 years old! Half your age is 17 years. Enter a number... 5 Half of 5 = 2.5 Tell me your name, would you like to try a test? Yes or No. yes The question is: What is the square root of 36? seven Sorry, you're wrong. Have a good day!

      Oh, no - you've inherited the same indentation style!

      :-)

      (welcome, and good job .. much more ambitious than those silly 'hello world' programs ;-})

      if "6" eq lc ($answertwo);

      <kidding>
      I'm very interested in knowing the uppercase of "6" :)
      </kidding>

      Lots of goodies in there. Good stuff!

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://508135]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (11)
As of 2014-09-02 09:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite cookbook is:










    Results (21 votes), past polls