Question

In python! Objective: students will be able to 1.access string elements by index operator 2.search for...

In python!

Objective:

students will be able to

1.access string elements by index operator

2.search for simple pattern in strings

Specification:

Biologists use a sequence of letters A, C, T, and G to model a genome. A gene is a substring of a genome that starts after a triplet ATG and ends before a trilet TAG, TAA, or TGA. The length of a gene string is a multiple of 3 and the gene does not contain any of the triplets ATG, TAG, TAA, and TGA. Write a program that prompts the user to enter a genome and displays all genes in the genome. If no gene is found in the input sequence, the program displays "No gene is found". Here are the sample runs:

Enter a genome string: TTATGTTTTAAGGATGGGGCGTTAGTT [ENTER]

TTT

GGGCGT

Enter a genome string: TGTGTGTATAT [ENTER]

No gene is found

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Program:

Sample output:

RUN1:

RUN2:

Code to copy:

#define main method
def main():

    #prompt the user to enter genome string
    print("Enter a genome string: ")
    string=input();

    #declare all the required variables
    i=0
    found=0
    start=-1

    #find the length of the string
    num=len(string)
    for i in range(num-2):

        #find the substring of genome string
        triplet=string[i:i+3]

        #compare the substring with following strings
        if triplet=="ATG":
            start=i+3
        elif triplet=="TAG" or triplet=="TAA" or triplet=="TGA" and start!=-1:
            gene=string[start:i]
            if len(gene)%3==0:
                found=1

                #print the substring
                print(gene)
                start=-1
    #check if there is no gene string
    if found==0:
        print("no gene is found")         
main()

  

Add a comment
Know the answer?
Add Answer to:
In python! Objective: students will be able to 1.access string elements by index operator 2.search for...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT