Homework#4

You might also like

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 2

print "My name is Lw, No.9700001.

\n";
print "This is my homework #4.\n";
$|=1;
#The amino acid codes.##########################
@code=(A,C..I,K..N,P..T,V,W,Y);
#The 20 amino acid codes don't contain "BJOUXZ".
while (1){
print "Which work do you want to run? \n(1,2,3=homework1,2,3 leave=0): "
;
chomp($k=<STDIN>);
if ($k==0){
last; #0NX
}
print "\n============================= Homework ${k} ===================
===============\n";
if ($k==1){
print "This is the homework1.\n";
print "The random RNA seuqence is\n";
generate(72);
}
elsif ($k==2){
print "This is the homework2.\n";
print "Please enter the number of the residues for a random prot
ein sequence.\n";
while(1){
chomp($num=<STDIN>);
if(($num+=0)==0){
print "You don't enter a number, please try agai
n\n";
}else{last;}
}
print "The random protein sequence is\n";
protein($num);
}
elsif ($k==3){
print "This is the homework3.\n";
for($i=0;$i<120000;$i++){
$dieNum=int(rand(6));
for($j=0;$j<6;$j++){if($dieNum==$j){$die[$dieNum]+=1;}}
}
for($i=0;$i<6;$i++){print "The face ",$i+1," occurs $die[$i] tim
es.\n";}
}
print "\nPress Enter to continue...";
chomp($o=<STDIN>);
system("cls");
}#end of while
sub generate{
$str="";
$len=$_[0];
for($i=0;$i<$len;$i++){
my $base=int(rand(4));
if($base==0){$str.="A";next}
if($base==1){$str.="U";next}

if($base==2){$str.="C";next}
if($base==3){$str.="G";next}
}
print $str,"\n";
}
sub protein{
$proSe="";
$l=$_[0];
for($i=0;$i<$l;$i++){
my $base=int(rand(20));
$proSe.=$code[$base];
}
print $proSe;
}

You might also like