Can you help me with Perl assignment? -
Can you help me with Perl assignment? -
i have assignment in perl , need little help here. i've been trying solve while couldn't, help me it?
here question:
write programme creates 3 different variables, names of animals assigned them (one animal per variable). display 3 animals user. have random number generator pick 1 of 3 animals, , inquire user guess animal chosen. allow user know whether guessed correctly or not.
that part don't know "have random number generator pick 1 of 3 animals".
here code far:
#!/user/bin/perl #assignment1.pl utilize warnings; $a1 = "cat"; $a2 = "dog"; $a3 = "lion"; print "you have 3 animals: $a1 , $a2 , $a3"; $num = 1 + int( rand(3) ); # i'm not sure of print "\nchoose animal has been chosen?\n"; print "answer: "; $ans = <stdin>; chomp $ans; if ( $ans eq $num ) { print "\nyour guess correct!\n"; } else { print "your guess incorrect\n"; }
i don't know what's wrong code, if know how solve question, i'll thankful.
here's hint.
my $num = int rand 3;
will give 0, 1, or 2, (pseudo-)randomly.
if values stored in array, pick 1 $array[$pick]
. assignment utilize scalar variables, not array. can figure out how utilize scalars list?
perl variable-assignment
Comments
Post a Comment