1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 | #!/usr/local/bin/perl $totalcount=0; $mistake=0; $total=250; while ($totalcount<$total) { $no1= int ( rand ( time ))%30; $no2= int ( rand ( time ))%30; if ($no1==0) { $no1++; } if ($no2==0) { $no2++; } $plus= int ( rand ( time ))%2; $answer=0; $wronglook=0; GETINPUT: if ($plus==0) { $answer=$no1 + $no2; print "$no1 + $no2 =" ; if ($no1>$no2) { $wronglook=$no1 - $no2; } else { $wronglook=$no2 - $no1; } } else { $wronglook=$no1 + $no2; if ($no1>$no2) { print "$no1 - $no2 =" ; $answer=$no1 - $no2; } else { print "$no2 - $no1 =" ; $answer=$no2- $no1; } } $userinput = <STDIN>; chomp($userinput); if (length($userinput)==0) { print "Please input your answer\n" ; goto GETINPUT; } $totalcount++;; if ($userinput == $answer) { print "Great!!!! you did good job , the answer is Correct $userinput\n" ; } elsif($wronglook==$userinput) { print "Almost there!Let's take a second look at Operation sign is it + or -\n" ; goto GETINPUT; } else { $mistake++; print "wrong, the correct answer is " .$answer. "\n" ; } if ($totalcount%10==0) { $score= int (100-$mistake*100/$totalcount); $left=$total-$totalcount; $leftpercent= int ($totalcount*100/400); print "$totalcount problems done, " .$left. " to go. finishing " .$leftpercent. "\%. Score correct percentage rate " .$score. "\%\n" ; } } |