Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
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!

Replies are listed 'Best First'.
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?
[Lady_Aleena]: You could quote it. <c>perl -e 'print "1.0"'>/c> returns 1.0
[Lady_Aleena]: perl -e 'my $var = "1.0"; print $var;' if it is in a variable also returns 1.0, though perl -e 'my $var = 1.0; print $var;' returns 1.
[1nickt]: In my case I can simply pass sprintf '%.1f', 1.0 (to Types::Standard:: Int), but what if you didn;t know the precision of the number you were working with? Seems I must be missing something. Oh well, my test list is complete, mooving on ...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (7)
As of 2017-05-24 18:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?