Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re^2: Teaching Children How to Program

by Panda (Scribe)
on Nov 14, 2005 at 09:54 UTC ( #508250=note: print w/ replies, xml ) Need Help??


in reply to Re: Teaching Children How to Program
in thread Teaching Children How to Program

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!


Comment on Re^2: Teaching Children How to Program
Select or Download Code
Re^3: Teaching Children How to Program
by Tanktalus (Canon) on Nov 14, 2005 at 21:52 UTC

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

    :-)

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

Re^3: Teaching Children How to Program
by ikegami (Pope) on Nov 16, 2005 at 02:00 UTC
    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://508250]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (12)
As of 2015-07-02 21:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (45 votes), past polls