xr6turbo has asked for the wisdom of the Perl Monks concerning the following question:
Hey Monks, Just starting off in perl (and programming in general) and need to do an exercise but a bit confused on the process.
Trying to create a script that will ask the user to enter a number between 1 and 5 and for it to print a colour represented e.g. if they enter 1, Blue comes up or 3, red gets printed. I've done a bit of research and I know I need to create an array (@) but not too clear on how to do so.
After that I need to assign an emotion to the colour e.g. blue = calm, red = angry. I'd also like to know how to incorporate modulus into this so on even/odd number inputs I can print it out (think ill need an if/else statement for this?)
At the end I'd like it to look like this:
Please enter a number between 1 and 5:
1
Blue. Even. Calm
So far I've got the code below and have no idea how to finish or even progress, any ideas?
print "Please enter a number between 1 and 5 (inclusive) below:"; my $number = <STDIN>; chomp($number); my @colours = ("red", "green", "blue", "purple", "black"); my %table = ( 1 => "angry" 2 => "sick" 3 => "calm" 4 => "worried" 5 => "sad" );
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Beginner here - basic help
by choroba (Cardinal) on Mar 26, 2015 at 13:28 UTC | |
|
Re: Beginner here - basic help
by toolic (Bishop) on Mar 26, 2015 at 13:29 UTC | |
by jeffa (Bishop) on Mar 26, 2015 at 16:39 UTC | |
|
Re: Beginner here - basic help
by BillKSmith (Monsignor) on Mar 26, 2015 at 16:56 UTC |