Exercise 7.1D

From Earlham CS Department
Jump to navigation Jump to search

Return to Week 4
Exercise 5.3 in Beginning Perl for Bioinformatics

#!/usr/bin/perl -w
use strict;

#Damian Almiron
#Ex 7.1

#Pseudocode:
#Get amino acid input from user input.
#Randomly guess the chosen amino acid until user confirms guess.
#Radomly chose 1 amino acid from an array of four amino acids.
#Declare variables (

my $amino_acid;
my $guess;
my @aa = ('A', 'B', 'C', 'D', 'E', 'F', 'G');
my $aa;
my $input;

#Ask user to choose an amino acid:

print "I will attempt to guess the amino acid you chose.\n";
print "Choose one of the following amino acids A,B,C,D,E,F or G:\n";

$amino_acid = <STDIN>;

chomp $amino_acid;

#Seed the random number generator

srand(time|$$);

#Guess an Amino Acid (not sure about the code here- refer to pg121)
do {

    $guess = $aa[int(rand(scalar @aa))];

    print "Is \"$guess\" your aa? Type \"Y\" if yes and \"N\" if no.\n";

    $input = <STDIN>;

} until($input =~ /^s*y/i);

exit;